繁体   English   中英

如何操纵熊猫DataFrame绘制ggplot直方图

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

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