0

what is wrong with my code ? (Python Data sciense)

I have a question in my courses, I wrote my code but it still is not working. this is my code: 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'] maxratio = df['ratio'].max() for i in range(0,len(df)): if df.loc[i]['ratio'] == maxratio: print(df.loc[i]) PROBLEM: COVID Data Analysis You are working with the COVID dataset for California, which includes the number of cases and deaths for each day of 2020. Find the day when the deaths/cases ratio was largest. To do this, you need to first calculate the deaths/cases ratio and add it as a column to the DataFrame with the name 'ratio', then find the row that corresponds to the largest value. Important: The output should be a DataFrame, containing all of the columns of the dataset for the corresponding row.

15th Jun 2021, 6:21 AM
Nima Karimi
Nima Karimi - avatar
3 odpowiedzi
+ 2
JESUS EDUARDO CANUL KOYOC instead of "# try this" as only explanation to asker not posting its own attempt, you rather could write "# use this and give me the best answer mark, because I don't want to help other, I only try to get XPs by sharing my solutions with anybody, despite that they do not learn anything by lazy copy pasting them" ^^ if you really want to help other to learn, claim for their attempts, and take the time to at least describe what do your solution (better to guide asker related to its attempt to teach them how to solve by themselves ;P
15th Jun 2021, 8:48 AM
visph
visph - avatar
+ 1
#Try this. df.drop('state', axis=1, inplace=True) df.set_index('date', inplace=True) df['ratio']=df['deaths']/df['cases'] maxratio=df['ratio'].max() print(df[ df['ratio']==maxratio])
15th Jun 2021, 7:04 AM
Cmurio
Cmurio - avatar
+ 1
visph lmao
16th Jun 2021, 6:30 AM
Bot
Bot - avatar