[英]plot: group by multiple colmuns pandas
id date load Instant DayType Month Day sort
0 2013-02-02 4667.341595 46 6 2 2 4667.341595
1 2013-02-02 4620.702889 47 6 2 2 4620.702889
2 2013-05-12 -4439.333624 3 0 5 12 4439.333624
3 2013-05-12 -4409.947044 4 0 5 12 4409.947044
4 2013-05-12 -4369.322473 5 0 5 12 4369.322473
嗨,我有一個功能rmse:
def RMSE2(x):
return(np.sqrt(np.mean(x**2)))
負載是我們的x,我想繪制每一天類型的每個瞬時的均方根值的收益,這意味着我想在x瞬時和y中具有我的函數的收益以及7個不同的圖(每個daytype的一個圖)。
那是你要的嗎 ?
df.groupby('DayType')['load'].apply(lambda x:np.sqrt(np.mean(x**2)))
輸出:
DayType
0 4406.294544
6 4644.080789
Name: load, dtype: float64
columns = np.unique(final.DayType)
b = []
for i in columns:
daytype = final[final['DayType'] == i]
a = daytype[['load']].groupby(daytype['Instant']).apply(RMSE2)
b.append(a)
import matplotlib.pyplot as plt
plt.xticks(rotation=70)
fig_size = plt.rcParams["figure.figsize"]
fig_size[0] = 8
fig_size[1] = 8
for i in range(9):
x = range(48)
y = b[i]['load']
plt.plot(x,y)
plt.ylabel("Rmse")
plt.xlabel("Day")
plt.legend(range(9),loc="upper left", bbox_to_anchor=[0, 1],
ncol=2, shadow=True, title="Legend", fancybox=True)
plt.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.