I have a large dataframe with dates and numbers for US states and counties. What I want to do is create a new row that does state level sum based on the county level numbers for each day.
An example dataframe, assume there are more rows and columns:
date state. county. sales .....
2020-01-22. CA 1 100
2020-01-22. CA 2 100
2020-01-22 FL 3 100
2020-01-22 FL 6 100
2020-01-22 NY 9 100
2020-01-22 NY 7 100
2020-01-23 CA 2 200
2020-01-23 FL 2 400
2020-01-23 NY 2 300
2020-01-24 CA 3 600
2020-01-24 FL 3 700
2020-01-24 NY 3 100
.
.
.
The county numbers are arbitrary. What I would want to do is to create a new row for each day for each state to do a sum of the sales for that day All other columns can be empty. The summation row for the states should not have any counties, so that it signals its state level.
Resulting dataframe:
date state. county. sales .....
2020-01-22. CA 1 100
2020-01-22. CA 2 100
2020-01-22 FL 3 100
2020-01-22 FL 6 100
2020-01-22 NY 9 100
2020-01-22 NY 7 100
2020-01-23 CA 2 200
2020-01-23 FL 2 400
2020-01-23 NY 2 300
2020-01-24 CA 3 600
2020-01-24 FL 3 700
2020-01-24 NY 3 100
2020-01-22. CA 200
2020-01-22. FL 200
2020-01-22. NY 200
.
.
.
Any help would be appreciated!