首页 > 解决方案 > 如何从我的熊猫表中创建特定行的折线图?

问题描述

      PARENT    Week    Month   Weekend
---------------------------------------
1010D   AX1      665    1633    687
1009A   BX1     1372    1484    1173 
1013B   CX1      895     941    777 
1007B   DX1      829     932    773

这是我的 mydata.csv。(抱歉,我无法使用 stackoverflow 格式对齐特定列下的行值。@glhr

如何使用 Pandas 在NAME列下为 Week、Month 和 Weekend 的值绘制 BX1 的折线图?

标签: pandaschartsline

解决方案


If only unique value BX1 value after filtering by boolean indexing transpose and add DataFrame.squeeze for convert one column DataFrame to Series and plot by plot.bar:

df.loc[df['NAME'] == 'BX1', ['Week','Month','Weekend']].T.squeeze().plot.bar()

Or:

df.loc[df['NAME'] == 'BX1', ['Week','Month','Weekend']].T.squeeze().plot()

推荐阅读