Worst Day problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Worst Day problem

The statement of one of the tasks of the Python for Data Science course is as follows: "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." Okay, actually, it's easy. I decided to use grouping, so I wrote the following code: https://code.sololearn.com/c22K70hZRp59/?ref=app You can make sure that if you enter the name of the month correctly, this program works correctly. But when I try to submit this solution, an error occurs: "The code is trying to access the column "cases" in the dataframe, but it is using the wrong syntax. The correct syntax would be df.loc[m]." But the KeyError in my program occurs if and only if the month is entered incorrectly! Then I decided to find out what exactly the tester program sends as input to my program. Let's modify the code a bit: https://code.sololearn.com/cZIS9C1GfrTP/?ref=app (Yes, I assumed the tester program in 5th test case was sending the month number instead of the name.) Here is the error I got: "The code is trying to convert the string "Asd" into an integer, but this is not possible." In this regard, the question: Asd - what is this month?) And what output is expected from my program if the input does not match the name of any month?

13th Jan 2023, 4:49 PM
LimitWolf
LimitWolf - avatar
3 Answers
0
I'll answer my own question. If an incorrect month name is sent to the input, you must output an empty DataFrame. Then, for example, this code will work: https://code.sololearn.com/cKa45biS1Hee/?ref=app
13th Jan 2023, 5:24 PM
LimitWolf
LimitWolf - avatar
0
did you show complete task or part of it
13th Jan 2023, 9:09 PM
Smith Welder
Smith Welder - avatar
0
Smith Welder, here is the full text of the task: " 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 (!) The given code adds a month column to the dataset, and adds an index. Do not change that part of the code. " Thus, the condition of the problem doesn't say that incorrect data can be given as input (text that doesn't match the name of any month). But in the 5th test case, this is exactly what happens. I solved this problem. As it turned out in this case, the program expects an empty DataFrame.
14th Jan 2023, 9:29 AM
LimitWolf
LimitWolf - avatar