Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import pandas as pd
  2. from pandas import ExcelWriter
  3. import time
  4. import random
  5.  
  6. then = time.time() #Time before the operations start
  7.  
  8. #reads in template data. Keeps leading zeros in column B and prevents "NaN" from appearing in blank cells.
  9. df = pd.read_excel('Contracts1.xlsx', converters = {'Document Key Co' : lambda x: str(x)}, na_filter = False)
  10.  
  11. #reads over account values and copies each account to contract, etc.
  12. concats = []
  13. for x in df.account.values:
  14.     concats.append(df.copy())
  15.     concats[-1].account = x
  16. pd.concat(concats)
  17.  
  18. #writes data into new excel spreadsheet and saves to folder
  19. #pd.concat(concats).to_excel("E9 Mass Import.xlsx", index=False)
  20. writer = ExcelWriter('E9 Mass Import.xlsx', datetime_format='m/dd/yy', date_format='m/dd/yy')
  21. pd.concat(concats).to_excel(writer,'Sheet1', index=False)
  22. writer.save()
  23.  
  24. now = time.time() #Time after it finished
  25.  
  26. print("Waking the hamsters took: ", now-then, " seconds")
  27. input("Press enter to exit")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement