2017-06-13 75 views
0
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:情節:由多個colmuns組大熊貓

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

負荷是我們的X我想繪製的RMSE每個瞬間的每一天類型的回報是不是意味着我要在x瞬間和y中返回我的函數和7個不同的情節(每種情態的情節)。

+0

請修改的問題,最後一條語句是模糊的。 – suvy

+0

謝謝你我找到解決方案 –

+0

如果你發現解決方案,請在這裏發佈答案,在stackoverflow的精神,它可能會幫助其他人。 – suvy

回答

0
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() 
0

這是你想要的嗎?

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

輸出:

DayType 
0 4406.294544 
6 4644.080789 
Name: load, dtype: float64 
+0

謝謝我發佈了answr –