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

Hidden cases

Hi all! I have done a challenge in Pandas, 18.2 Python for Data Science https://www.sololearn.com/learning/1161 Given the COVID data, find the day with maximum cases in a given month. Take a month name as input and output the row that corresponds to the day with the maximum number of cases in that month. You can filter the DataFrame for the given month first, and then select the row with the maximum cases. Important: The output should be a DataFrame, which includes all the columns. For example, for the month of February, the expected result would be: cases deaths month date 2020-02-26 15 0 February Here is my code>>> 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) by_month = df.groupby('month') month_df = by_month.get_group(input()) sort_df = month_df.sort_values(by=['cases']) print(sort_df.tail(1)) The output is correct but there is one hidden case and I could not get through it because it is hidden... What say you? Why cases are hidden for what purpose?

12th Dec 2021, 1:35 PM
Andrei Shanko
Andrei Shanko - avatar
6 Answers
+ 1
Andrei Shanko Test cases are hidden because you have to write a logic which can satisfy all conditions. If test cases are not hidden then you will write Hard Code logic to get output but remember there are only few test cases if there are thousands test cases then what? So your output is correct for one test case because that is not hidden and you have written logic according to open test cases. Example: if I know the sum of 2 input is 8 then I will do 4 + 4 = 8 But if test case is hidden and output is 10 then? How would you write your logic to get 10. So for this you have to write generic logic like print(a + b) ## here a and b are inputs Now whatever inputs will be, you will get output according to that.
12th Dec 2021, 3:40 PM
A͢J
A͢J - avatar
0
Thanks, I have got your point though you missed mine. You are talking about tailoring but I did not tailor my code to the output. I checked that twice in PyCharm it is working for every month in a year. And, I believe, there is a strong logic in it. In case you have caught any mistakes in this code, please give me a clue. You can check it out. https://www.sololearn.com/uploads/ca-covid.csv
12th Dec 2021, 7:05 PM
Andrei Shanko
Andrei Shanko - avatar
0
Andrei Shanko Take month as input month = input() Filter dataframe on the given month df = df[df['month'] == month] Select the row with maximum cases No need to sort dataframe just use max() function. maxcases = df['cases'].max() Now compare the cases with maximum case to get corresponding rows.
12th Dec 2021, 8:16 PM
A͢J
A͢J - avatar
0
Oh, yes. Of course, I did this way. In this case, your output will be a number but in the task, we need to get a DataFrame. >>>Important: The output should be a DataFrame, which includes all the columns. For example, for the month of February, the expected result would be: cases deaths month date 2020-02-26 15 0 February >>> It works only through the fucn df.head(1) or df.tail(1), so we need sorting.
13th Dec 2021, 6:55 AM
Andrei Shanko
Andrei Shanko - avatar
0
I don’t have pro version so I’m not sure but, maybe the hidden case is for January. There were more than 1 cases that month. If they want all the days with maximum cases for specific month, my code should work: https://code.sololearn.com/cNaQv6OrwJ1F/?ref=app
6th Jan 2022, 3:43 AM
Nadia
Nadia - avatar
0
It works, Nadia. Thanks a lot.
6th Jan 2022, 8:33 AM
Andrei Shanko
Andrei Shanko - avatar