Guest User

Untitled

a guest
Jul 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. 00 : 123,000,444,220
  2. 01 : 500,000
  3. 0a : 30,444,555,120
  4. .
  5. .
  6. .
  7. ff : 45,002,221,222
  8.  
  9. import pandas
  10.  
  11. for i in range(4):
  12.  
  13. for j in range(10):
  14.  
  15. digits = str(i)+str(j)
  16. all_data = pandas.read_csv('/home/asus/data/arief_anbiya_{}.csv'.format(digits), chunksize = 100000, iterator = True) #Transform each csv data to DF.
  17. all_data = pandas.concat(all_data, ignore_index= True)
  18. all_data['account_group'] = [acc_id[0:2] for acc_id in all_data.account_id] #Adding a now column 'first_two' of each account_id (from current csv).
  19.  
  20. dummy = all_data.groupby(by = 'account_group').sum() #Sum of 'account_balance' of current DF grouped by 'first_two' (from current csv).
  21.  
  22. if i == 0 and j == 0: #Create the Series for the total 'account_balance' (grouped by 'first_two').
  23.  
  24. sum_of_groupby = dummy.account_balance
  25.  
  26. else: #Update the Series of total 'account_balance'.
  27.  
  28. for ft in set(all_data['account_group']): # unique_ft is all unique 'first_two' (from current csv).
  29.  
  30. try:
  31. sum_of_groupby[ft] += dummy.account_balance[ft]
  32. except:
  33. sum_of_groupby[ft] = dummy.account_balance[ft]
  34.  
  35. print('Done adding : arief_anbiya_{}.csv'.format(digits))
Add Comment
Please, Sign In to add comment