text_html_output_1.png
import pandas as pd

df_train = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/train.csv')
df_test = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/test.csv')
df_sub = pd.read_csv('/kaggle/input/covid19-global-forecasting-week-4/submission.csv')

by_ctry_prov = df_train.groupby(['Country_Region', 'Province_State'])[['ConfirmedCases', 'Fatalities']]
df_train[['NewCases', 'NewFatalities']] = by_ctry_prov.transform(lambda x: x.diff().fillna(0))
df_train[['NewCasesPct', 'NewFatalitiesPct']] = by_ctry_prov.transform(lambda x: x.pct_change().fillna(0))

df_train.sort_values('NewCases', ascending=False).head()

df_train[df_train.NewCases < 0].sort_values('NewCases')

df_train[df_train.NewFatalities < 0].sort_values('NewFatalities')

df_train[df_train.Fatalities > df_train.ConfirmedCases]

df_train[(df_train.NewCasesPct > 0.4) & (df_train.NewCases > 1000)]