每 2 列绘制一次

阿斯达

我有一个 df 比较新旧数据。有没有办法每两列绘制一次,以 x 轴作为日期?或者根据日期绘制具有相同根名称的所有列。所以每个水果应该有 1 个折线图。

df
    date        apple_old     apple_new    banana_old   banana_new
0   2015-01-01        5          6             4              2          
...

我试过:

for col in df.columns:
    if col .endswith("_old") and col .endswith("_new"):
        x = x.plot(kind="line", x = date, y =(f"{col}_old", f"{col}_new"))
耶斯列

用:

df1 = df.set_index('date')

df1.columns = df1.columns.str.split('_', expand=True)

for lev in df1.columns.levels[0]:
    print (df1[lev].plot())

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章