-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bldg_Read_test.py
62 lines (42 loc) · 1.91 KB
/
Bldg_Read_test.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
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import *
#Calculate the average "statistic" for each building type
def avg_statistic_per_bldgtype(cnty, name, building_type, statistic, ylabel, title):
from matplotlib.pyplot import figure
avg_datas = np.array([], dtype=np.float64)
building_count = []
print "# of builidngs", cnty[building_type].unique().size , statistic
for i in range(cnty[building_type].unique().size):
bldgtype = cnty[building_type].unique()[i]
avg_data = cnty[cnty[building_type]==bldgtype][statistic].mean(skipna=True)
building_count.append(cnty[cnty[building_type]==bldgtype][statistic].count())
print "cnt", bldgtype, avg_data, building_count[i]
avg_datas = np.append(avg_datas, avg_data)
fig1 = plt.figure(figsize=(18, 6))
plt.title(title)
plt.xlabel("Building Type")
plt.ylabel(ylabel, fontsize = 12)
bars = plt.bar(cnty[building_type].unique(), avg_datas)
i = 0
for bar in bars:
yval = bar.get_height()
plt.text(bar.get_x()+0.3, yval + (yval*0.01), str(building_count[i]))# + " Buildings")
i += 1
fig1.tight_layout()
# plt.show()
fig1.savefig('plots/'+ name + statistic + '_March71fig.png')
return avg_datas
#
def avg_statistic_per_bldgtype_no_plot(cnty, building_type, statistic):
from matplotlib.pyplot import figure
avg_datas = np.array([], dtype=np.float64)
building_count = []
for i in range(cnty[building_type].unique().size):
bldgtype = cnty[building_type].unique()[i]
avg_data = cnty[cnty[building_type]==bldgtype][statistic].mean(skipna=True)
building_count.append(cnty[cnty[building_type]==bldgtype][statistic].count())
avg_datas = np.append(avg_datas, avg_data)
i += 1
return avg_datas, building_count