Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from pandas import ExcelWriter
- import time
- import random
- then = time.time() #Time before the operations start
- #reads in template data. Keeps leading zeros in column B and prevents "NaN" from appearing in blank cells.
- df = pd.read_excel('Contracts1.xlsx', converters = {'Document Key Co' : lambda x: str(x)}, na_filter = False)
- #reads over account values and copies each account to contract, etc.
- concats = []
- for x in df.account.values:
- concats.append(df.copy())
- concats[-1].account = x
- pd.concat(concats)
- #writes data into new excel spreadsheet and saves to folder
- #pd.concat(concats).to_excel("E9 Mass Import.xlsx", index=False)
- writer = ExcelWriter('E9 Mass Import.xlsx', datetime_format='m/dd/yy', date_format='m/dd/yy')
- pd.concat(concats).to_excel(writer,'Sheet1', index=False)
- writer.save()
- now = time.time() #Time after it finished
- print("Waking the hamsters took: ", now-then, " seconds")
- input("Press enter to exit")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement