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