COVID Data Analysis | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

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])

7th Apr 2021, 11:14 AM
Sylvanast
Sylvanast - avatar
17 Answers
+ 11
And finally if don't understand u can look on my solution https://code.sololearn.com/co287aYKt37I/?ref=app
7th Apr 2021, 1:44 PM
Илья Мирошник
Илья Мирошник - avatar
+ 6
For filter date (why u comment set index line?) U can use df[df["ratio"]==df["ratio"].max()]
7th Apr 2021, 1:43 PM
Илья Мирошник
Илья Мирошник - avatar
+ 5
Ratio u can add very easy just df["ratio"]=df["death"]/df["cases"]
7th Apr 2021, 1:40 PM
Илья Мирошник
Илья Мирошник - avatar
+ 5
For get max value u can use max function. df["ratio"].max()
7th Apr 2021, 1:40 PM
Илья Мирошник
Илья Мирошник - avatar
+ 2
Alright, Thank you very much 😁
7th Apr 2021, 1:59 PM
Sylvanast
Sylvanast - avatar
+ 2
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
9th Apr 2021, 9:11 AM
Илья Мирошник
Илья Мирошник - avatar
+ 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
29th Apr 2021, 4:19 PM
Sylvanast
Sylvanast - avatar
+ 2
Aripov Shahriyor because u try get row by index but input value
29th Apr 2021, 4:37 PM
Илья Мирошник
Илья Мирошник - avatar
+ 1
Илья Мирошник 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 [ ] ?
9th Apr 2021, 8:24 AM
Sylvanast
Sylvanast - avatar
+ 1
So, it is like when you define df[True] and then will print that line? Because if it false,it is not the maximum Илья Мирошник
9th Apr 2021, 10:55 AM
Sylvanast
Sylvanast - avatar
+ 1
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
9th Apr 2021, 11:02 AM
Илья Мирошник
Илья Мирошник - avatar
0
Can somebody explain why this solution doesn't work df['ratio']= df['death']/df['cases'] print(df.iloc[df['ratio'].max()])
26th Apr 2021, 5:47 AM
Aripov Shahriyor
Aripov Shahriyor - avatar
0
Thank you for your answers. I have just understood
9th May 2021, 5:31 PM
Aripov Shahriyor
Aripov Shahriyor - avatar
0
print(df.loc['31.12.20'])
21st Sep 2021, 5:57 AM
Khomi TAKAYANAGI
Khomi TAKAYANAGI - avatar
0
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.loc[df['ratio']==df['ratio'].max()] print(maxratio) its work
20th Jun 2022, 10:18 AM
Mr Shivaji Narayan Rathod
0
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'] print(df[(df["ratio"]== df['ratio'].max())])
28th Sep 2023, 7:08 AM
MD. Omar Faruk Maruf
MD. Omar Faruk Maruf - avatar
- 1
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.loc[df['ratio']==df['ratio'].max()] print(maxratio)
19th Oct 2021, 11:19 PM
Ammar M Almansor
Ammar M Almansor - avatar