worst day challange | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

worst day challange

following is my code for worst day challange. It satishfies first 4 cases but fails for 5th case. I am not able to figure out the issue . Please help me if anybody import pandas as pd df = pd.read_csv("/usercode/files/ca-covid.csv") df.drop('state', axis=1, inplace=True) df['date'] = pd.to_datetime(df['date'], format="%d.%m.%y") df['month'] = df['date'].dt.month_name() df.set_index('date', inplace=True) ip1=input() ip = ip1.title() a = df.groupby("month").get_group(ip).cases.max() #print(a) print(df[(df["cases"]==a)])

22nd Dec 2021, 12:19 PM
Chidambar 2400
Chidambar 2400 - avatar
2 Answers
+ 1
Chidambar 2400 I'm not sure if it is the same challenge, but anyway, maybe this can help you: import pandas as pd df = pd.read_csv("/usercode/files/ca-covid.csv") df.drop('state', axis=1, inplace=True) df.set_index('date', inplace=True) df['ratio'] = df['deaths'] / df['cases'] print (df[df['ratio'] == df['ratio'].max()])
23rd Dec 2021, 7:01 PM
Maisu
Maisu - avatar
+ 1
The following code should work perfectly: import pandas as pd df = pd.read_csv("/usercode/files/ca-covid.csv") df.drop('state', axis=1, inplace=True) df['date'] = pd.to_datetime(df['date'], format="%d.%m.%y") df['month'] = df['date'].dt.month_name() df.set_index('date', inplace=True) month = input() newdata = df[(df["month"]==month)] worst_day = newdata [(newdata['cases']== newdata ['cases'].max())] print (worst_day )
13th Aug 2022, 10:42 AM
roxsie
roxsie - avatar