[英]How to manipulate pandas DataFrame to plot ggplot histogram
我正在嘗試給定熊貓數據框的直方圖,如下所示:
weekday ENTRIESn_hourly
0 0 604.620120
1 1 1084.888769
2 2 1307.073259
3 3 1335.901803
4 4 1305.176382
5 5 1333.800773
6 6 809.925317
它有2列df.weekday
和df.ENTRIESn_hourly
如何繪制ggplot直方圖,以便x軸為工作日,y軸為ENTRIESn_hourly?
到目前為止,我想到了這個:
plot = ggplot.ggplot(new_df, ggplot.aes(x='weekday')) +\
ggplot.geom_histogram(binwidth=1) +\
ggplot.ggtitle('NYC Subway ridership by day of week') +\
ggplot.xlab('Week day (0=Sunday)') +\
ggplot.ylab('Entries')
但第一行拋出錯誤“ pivot_table()得到了意外的關鍵字參數“ rows””
我想這就是你想要的。 它使用stat ='identity',因為直方圖已經在df中進行了計算。
plot = ggplot.ggplot(new_df, ggplot.aes(x='weekday', y='ENTRIESn_hourly')) +\
ggplot.geom_bar(stat='identity') +\
ggplot.ggtitle('NYC Subway ridership by day of week') +\
ggplot.xlab('Week day (0=Sunday)') +\
ggplot.ylab('Entries')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.