How to undo column aggregation on pandas dataframe

Viewed 194

I have a dataframe with columns that are an aggregation of corona virus cases over time.

Data Table

I need the data in the date columns to be the new number of cases for that day instead of the aggregation. So for example, I am trying to get the first row to be like

Anhui, Mainland China, 1, 8, 6

I think there might be a quick pandas way to do this but can't find it by google searching. A brute force method would be okay too. Thanks!

1 Answers

You can take take the finite difference along constant rows in the dataframe. If df is a copy of the numerical part of the dataframe then the following will do it:

df.diff(axis=1)

Documentation

Related