1
我有一個事件列表,我想在圖表上顯示每週每小時每小時發生多少次,如下所示: Example of the graph i want (每一行是一天,x軸是一天中的時間,y軸是事件的數量)如何將事件列表中的矩陣顯示在Panda中
由於我是熊貓新手,我不確定最好的方法是什麼,但這是我的方式:
x = [(rts[k].getDay(), rts[k].getHour(), 1) for k in rts]
df = pd.DataFrame(x[:30]) # Subset of 30 events
dfGrouped = df.groupby([0, 1]).sum() # Group them by day and hour
#Format to display
pd.DataFrame(np.random.randn(24, 7), index=range(0,24), columns=['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'])
問題是,我怎麼能從我的數據框與數據分組到矩陣24x7按要求顯示?
我試着as_matrix,但只給了我一維數組,而我想我的數據框的索引是我的矩陣中的索引。
print(df)
2
0 1
0 19 1
23 1
1 10 2
18 3
22 1
2 17 1
3 8 2
9 3
11 3
13 1
19 1
4 7 1
9 1
14 1
15 1
18 1
5 1 2
7 1
13 1
19 1
6 12 1
感謝您的幫助:) 安東尼
謝謝你這麼多,這正是我需要:) – Antoine