I am trying to get the percentage change in value of today compared to yesterday, for every day in the dataframe. This is the line that throws the error-
import pandas as pd
df = pd.DataFrame({'new_cases':[368060.0,
357316.0,
382146.0,
412431.0,
414188.0,
401078.0,
403405.0,
366494.0,
329942.0]})
df['percent_increase_cases'] = df['new_cases'].apply(pd.Series.pct_change)
The formula I am using is
percent_increase = (today's cases - yesterday's cases) / yesterday's cases * 100
It works if I use the code below but I wanted to make it cleaner.
df['percent_increase_cases'] = (df['new_cases'].diff(1)) / df['new_cases'].shift(1) * 100