【问题标题】:Pandas combine two line charts into onePandas 将两个折线图合二为一
【发布时间】:2021-11-28 06:10:16
【问题描述】:

在 Pandas 中,我有以下两个语句,它们都生成折线图。

df_merged.loc[df_merged['Country'] == 'The United Kingdom', ['DateReported', 'NewCases']].set_index('DateReported').plot.line(figsize=(10,6))

df_merged.loc[df_merged['Country'] == 'The United Kingdom', ['DateReported', 'DailyVaccinations']].set_index('DateReported').plot.line(figsize=(10,6))

两种说法是相同的。不同之处在于,在第一个中我使用“NewCases”,而在第二个中使用“DailyVaccinations”列

这就是 df_merged 的​​样子 有 21 列,但我只对绘制“NewCases”和“DailyVaccinations”感兴趣。

我想将这两个折线图合二为一。我该怎么做?

【问题讨论】:

标签: python pandas matplotlib


【解决方案1】:

没有更多细节很难回答,这是一般逻辑。首先对英国数据进行切片,设置索引,对感兴趣的列进行子集化并绘图

(df_merged.query('Country == "The United Kingdom"')
          .set_index('DateReported')
          [['NewCases', 'DailyVaccinations']]
          .plot.line(figsize=(10,6))
)

没有输出,因为没有提供数据

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 2016-02-27
    • 2015-12-30
    相关资源
    最近更新 更多