Worst Day - Python for Data Science
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. 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) month = input() newdata = df[(df['month']==month)] data = pd.DataFrame(newdata) print(data.groupby('month')['cases'].max()) ------------------- My output: -------------------- month April 2334 Name: cases, dtype: int64 ----------------------- Expected output: cases deaths month date 2020-04-29 2334 77 April ------------------ Please help, I tried my best but it seems like I can't figure it out how to output the same format as they have. I have used all the elements I learned so far from Pandas to did this. Please help! Thank you