How to undo column aggregation on pandas dataframe

Marcus Gallegos :

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!

Yaniel Cabrera :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=360780&siteId=1