简体   繁体   English

剧情:按多只大熊猫分组

[英]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

Hi I have a function rmse: 嗨,我有一个功能rmse:

def RMSE2(x):
    return(np.sqrt(np.mean(x**2)))

Load is our x I want to plot the return of rmse for each instant for each day type is mean I want to have in x instant and in y the return of my function AND 7 different plot (a plot for each daytype). 负载是我们的x,我想绘制每一天类型的每个瞬时的均方根值的收益,这意味着我想在x瞬时和y中具有我的函数的收益以及7个不同的图(每个daytype的一个图)。

Is that what you want ? 那是你要的吗 ?

df.groupby('DayType')['load'].apply(lambda x:np.sqrt(np.mean(x**2)))

output : 输出:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM