0

In Pandas, I have the following two statements, which are both producing line charts.

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

enter image description here

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

enter image description here Both statements are identical. The difference is that in the first one I use 'NewCases' and in the second one 'DailyVaccinations' column is used

This is how df_merged looks like enter image description here There are 21 columns, but I am just interested in plotting 'NewCases' and 'DailyVaccinations'.

I would like to combine those two line charts into one. How can I do it?

lyubol
  • 119
  • 9
  • 1
    Please provide a sample of the original data – mozway Nov 28 '21 at 06:13
  • If you need assistance formatting a small sample of your DataFrame as a copyable piece of code for SO see [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker Nov 28 '21 at 06:13

1 Answers1

0

Difficult to answer without more details, here is the general logic. Slice first the UK data, set your index, subset the columns of interest and plot

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

No output as no data was provided

mozway
  • 194,879
  • 13
  • 39
  • 75