﻿

Untitled

a guest
Dec 15th, 2019
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import pandas as pd
2. import numpy as np
3. import matplotlib.pyplot as plt
4.
6. fig, ax = plt.subplots(figsize = (10,5))
7. def datetime(column):
8.     return np.array([list(map(int, string.split(' ')[0].split('-'))) for string in column])
9.
10. df['year'] = datetime(df['ВРЕМЯ'].to_numpy())[:, 0]
11. df['month'] = datetime(df['ВРЕМЯ'].to_numpy())[:, 1]
12. df['day'] = datetime(df['ВРЕМЯ'].to_numpy())[:, 2]
13.
14. for year in np.unique(df['year']):
15.     print('average monthly income in ', year, ' : ', (df.loc[(df['year'] == year) & (df['КАТЕГОРИЯ'] == 'Доходы')].sum()['СУММА'])/len(np.unique(df.loc[(df['year'] == year), ['month']])))
16.
17. for year in np.unique(df['year']):
18.     for category in np.unique(df.loc[(df['year'] == year)&(df['КАТЕГОРИЯ'] != 'Доходы'), ['КАТЕГОРИЯ']]):
19.         print('Monthly average expenses on ', category, ' in year ', year, ' : ', df.loc[(df['year'] == year) & (df['КАТЕГОРИЯ'] == category), ['СУММА']].sum()['СУММА']/len(np.unique(df.loc[(df['year'] == year), ['month']])))
20.     print()
21.
22. fd = df.loc[df['КАТЕГОРИЯ'] != 'Доходы'].pivot_table('СУММА', ['year', 'КАТЕГОРИЯ'], 'month', aggfunc = {'СУММА': sum})
23. fd.plot.bar()
24.
25. print(fd)
26. xs = []
27. ys = []
28. for year in np.unique(df['year']):
29.     for month in np.unique(df.loc[df['year'] == year, 'month']):
30.         for day in np.unique(df.loc[(df['year'] == year)&(df['month'] == month), 'day']):
31.             xs.append(str(year)+'-'+str(month)+'-'+str(day))
32.             ys.append(df.loc[(df['year'] == year)&(df['month'] == month)&(df['day'] == day), 'СУММА'].sum())
33.
34.
35. ax.plot(xs, ys)
36. ax.tick_params(
37.     axis='x',          # changes apply to the x-axis
38.     which='both',      # both major and minor ticks are affected
39.     bottom=False,      # ticks along the bottom edge are off
40.     top=False,         # ticks along the top edge are off
41.     labelbottom=False) # labels along the bottom edge are off
42. plt.show()
RAW Paste Data