Guest User

Untitled

a guest
Jun 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. df = pd.read_csv(r'C:downloadexample.csv', sep=';', decimal=',',
  2. encoding='cp1251', dayfirst=True, parse_dates=['Time Period'])
  3.  
  4. df['Share/month'] = (df.groupby(['Sites',
  5. 'Source Type from Overview',
  6. pd.Grouper(key='Time Period', freq='1MS')])
  7. ['Traffic Share']
  8. .transform(lambda x: x/x.sum()))
  9.  
  10. In [267]: df
  11. Out[267]:
  12. Time Period Source Type from Overview Traffic Share Sites Share from SourceType Share/month
  13. 0 2017-05-01 Черный 0.493767 чай 0.579027 0.579027
  14. 1 2017-05-01 Черный 0.357690 чай 0.419453 0.419453
  15. 2 2017-05-01 Зеленый 0.099872 чай 1.000000 1.000000
  16. 3 2017-05-01 Белый 0.033291 чай 1.000000 1.000000
  17. 4 2017-05-01 Красный 0.012072 чай 0.857143 0.857141
  18. 5 2017-05-01 Красный 0.002012 чай 0.142857 0.142859
  19. 6 2017-05-01 Черный 0.001296 чай 0.001520 0.001520
  20. .. ... ... ... ... ... ...
  21. 19 2017-07-01 Черный 0.387125 чай 0.464413 0.464413
  22. 20 2017-07-01 Зеленый 0.113402 чай 1.000000 1.000000
  23. 21 2017-07-01 Порошковый 0.026510 чай 1.000000 1.000000
  24. 22 2017-07-01 Красный 0.013255 чай 1.000000 1.000000
  25. 23 2017-07-01 Белый 0.013255 чай 1.000000 1.000000
  26. 24 2017-07-01 Черный 0.000000 чай 0.000000 0.000000
  27. 25 2017-07-01 Зеленый 0.000000 чай 0.000000 0.000000
  28.  
  29. [26 rows x 6 columns]
Add Comment
Please, Sign In to add comment