-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsummary_graph_gencons.py
61 lines (52 loc) · 1.99 KB
/
summary_graph_gencons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pandas as pd
import numpy as np
import os
year = input("Year: ")
selected = [
"202307",
"202308",
"202309",
"202310",
"202311",
"202312",
"202401",
"202402",
"202403",
"202404"
]
df = pd.DataFrame()
# if os.path.exists("processed_data/summary.csv"):
# df_in = pd.read_csv("processed_data/summary.csv", header=[0,1])
# df_in = df_in.drop([0])
# temp = df_in.columns.to_numpy()
# temp[0] = ('DAY_TYPE', None)
# temp[1] = ('PT_CODE', None)
# df_in.columns = pd.MultiIndex.from_tuples(temp)
# #print(df_in.columns)
# df_in.columns.set_names("month", level = 1)
# df_in = df_in.set_index([ ('DAY_TYPE', None), ('PT_CODE', None)])
# df_in.index.set_names("DAY_TYPE" , level=0)
# df_in.index.set_names("PT_CODE" , level=1)
for subdir, dirs, files in os.walk("processed_data"):
for file in files:
#print os.path.join(subdir, file)
filepath = os.path.join(subdir,file)
if "_summary_" in filepath:
if "node" in filepath:
df_plus = pd.read_csv(filepath)
month_tag = os.path.split(subdir)[1]
if month_tag in selected:
#if year in month_tag:
df_plus.insert(0, "month", month_tag)
df = pd.concat([df, df_plus])
# if ('TOTAL_TAP_IN_VOLUME', month_tag) in df_in.columns:
# print(month_tag)
df1 = pd.pivot_table(df, index=["DAY_TYPE", 'PT_CODE'], columns=["month"], aggfunc={'TOTAL_TAP_IN_VOLUME': np.sum, 'TOTAL_TAP_OUT_VOLUME': np.sum})
#df1 = pd.concat([df1, df_in])
df1 = df1.groupby(["DAY_TYPE", 'PT_CODE']).sum()
#df1.to_csv("processed_data/summary2.csv")
df2 = df1.groupby(["DAY_TYPE"]).sum()['TOTAL_TAP_IN_VOLUME'].plot(kind="bar")
df2.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left',
ncol=6, mode="expand", fontsize='xx-small')
df2.tick_params(labelrotation=0)
df2.get_figure().savefig(f"graph_in_{year}.png", format='png')