Skip to content
Advertisement

How to generate 2-yaxis graphs on a panel data per id?

I have a dataset, df that looks like this:

Date Code City State Quantity x Quantity y Population Cases Deaths
2019-01 10001 Los Angeles CA 445 0 0
2019-01 10002 Sacramento CA 4450 556 0 0
2020-03 12223 Houston TX 440 4440 35000000 23 11
2021-07 10002 Sacramento CA 3220 NA 5444000 211 22

My start and end date are the same for all cities. I have over 4000 different cities, and would like to plot a 2-yaxis graph for each city, using something similar to the following code:

JavaScript

I would like to create a loop so that the code above runs for every Code that is related to a City, with quantity x and deaths, and it saves each graph made into a folder. How can I create a loop that does that, and stops every different Code?

Observations: Some values on df['Quantity x] and df[Population] are left blank.

Advertisement

Answer

If I understood you correctly, you are looking for a filtering functionality:

JavaScript
Advertisement