+ 1

Number of Cases(Worst Day) in Python for Data Science?

There seems to be a bug in that task. The input string is a month, January or February etc. and the job is to print out the maximum cases in one day in a specific month. The problem is just, that there is no maximum cases in the month of January. There are three cases in that month. One case a day on three different dates. The explanation doesn't say what to print out if there is no maximum in a given month, and that is why it keeps failing test case #5, and it doesn't make sense keep guessing the output, so I'm excited to hear if anybody has passed all five test cases. https://code.sololearn.com/ckv2QE5vSKGF/?ref=app

25th Mar 2021, 6:03 PM
Jan
Jan - avatar
4 Answers
+ 6
I checked the output of your code compared to mine for each month and it was the same (as far as I could see), but mine passes all test cases. I can only guess that there is some minor non-visible difference that it doesn't like. Anyway try this; month = input() df = df[df['month']==month] print(df[df['cases']==df['cases'].max()])
25th Mar 2021, 10:50 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
That's weird, but it must be that groupby that has one or more hidden characters that destroys the equal comparison, I think, but thanks for the help. I will check that later in an editor where I can see the ascii characters.
25th Mar 2021, 11:35 PM
Jan
Jan - avatar
+ 1
I have now analyzed both outputs and I haven't been able to find a single difference. The ascii characters and even the hex characters are completely the same. It must be the Python interpreter on the SoloLearn server, used on the test cases, that for some reason doesn't understand my code when there is no maximum, but still related to groupby.
26th Mar 2021, 6:59 PM
Jan
Jan - avatar
0
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 ) Lavanya signing off
5th Dec 2022, 11:48 AM
Lavanya Mangala