COVID Data Analysis project in data science with python | Sololearn: Learn to code for FREE!

+4

COVID Data Analysis project in data science with python

hi every body. i am so new in python, i had written this code for this question: 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. i do not understand what is problem exactly. can anyone help me? thanks a lot. 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'] a=df['ratio'].idxmax print(df.loc[[a]])

3/15/2021 9:39:48 AM

Mahsa Farahani

8 Answers

New Answer

+9

print(df[df['ratio'] == df['ratio'].max()])

+2

I resolved the exercise. Here is my code. https://code.sololearn.com/cYfoYT1a0Tgw/?ref=app

0

the link is not functional.

0

i editted @Wilbur Jaywright

0

Thanks, with question and answer of Igor Kostrikin I found error in my code

0

Did any one pass this project? I used print(df[df['ratio'] == df['ratio'].max()]) and got the output as follows cases deaths ratio date 10.03.20 7 1 0.142857 Unfortunately, the test case 1 doesn't let me pass. Could any one help me on this?

-1

print(df.loc[df['ratio'].idxmax()]) Idxmax() method returns the location of the maximum value.

-1

My way: 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'] y = df['ratio'].max() print(df[df['ratio'] == y])