 COVID Data Analysis | Sololearn: Learn to code for FREE!

+3

# COVID Data Analysis

Help me, I already found the answer but i don't know how to match it with the answer key Question : Phyton for Data Science 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. And 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.set_index('date', inplace=True) max = 0 maxindex = 0 ratio= [] for i in df.index: a= df["deaths"][i] / df["cases"][i] ratio.append(a) if (a > max): max = a maxindex = i df['ratio']=ratio #print(df) #print(maxindex) print(df.iloc[maxindex])

+4

Ratio u can add very easy just df["ratio"]=df["death"]/df["cases"]

+4

For get max value u can use max function. df["ratio"].max()

+4

And finally if don't understand u can look on my solution https://code.sololearn.com/co287aYKt37I/?ref=app

+3

For filter date (why u comment set index line?) U can use df[df["ratio"]==df["ratio"].max()]

+2

Maybe i can help you Aripov Shahriyor. Because [df['ratio'].max()]) didn't give output that iloc required. You can check Илья Мирошник answer. It is works

+1

Alright, Thank you very much 😁

+1

Can somebody explain why this solution doesn't work df['ratio']= df['death']/df['cases'] print(df.iloc[df['ratio'].max()])

+1

Aripov Shahriyor because u try get row by index but input value

0

Илья Мирошник I wanna ask something For filter date (why u comment set index line?) U can use df[df["ratio"]==df["ratio"].max()] Can you explain how we can specify df[ ] with boolean value inside the [ ] ?

0

Sylvanast what u mean? df["ratio"]==df["ratio"].max() generate list of true and false, but max ratio only one and it give only one 2. row 1. No max False 2. Max True 3. No max False ... N. No max False https://www.sololearn.com/post/1028491/?ref=app

0

So, it is like when you define df[True] and then will print that line? Because if it false,it is not the maximum Илья Мирошник

0

Mmm... df[True] return error because df don't have index True. Layout True of False get data from df if length layout true and false == length of df. and this data will be length of True in layout of True/False

0