I have a dataset like this:
| Year | City |
|---|---|
| 1905 | New York |
| 1906 | New York |
| 1906 | Boston |
| *** | *** |
| 2021 | Houston |
I wanted to add sumcum, so I did the following:
df["Count"]=1
df['cumsum']=df.groupby(['City'])['Count'].cumsum()
And it is working fine, although not sure if this was the best approach.
What I would like to do next is to transpose the data, but also fill all the gaps. Because occurrence of the cities is not consistent (e.g. Boston occurs in 1924 then again in 1928).
I would like to have this:
How can I make this with Pandas?
Thanks
