COVID Data Analysis - from course data science (python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

COVID Data Analysis - from course data science (python)

Did any one pass this project? "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." Link to this project: https://www.sololearn.com/learning/eom-project/1161/1162 I used the code below 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?

17th Mar 2021, 4:46 PM
Thoi Nhan NGO
Thoi Nhan NGO - avatar
15 Answers
- 2
Thanks Derrickee for your answer. Actually, your code is the same as mine with 1 redundant ' before the second df. I found out what is wrong with this project: - Do not change the link of the data source (the csv file) or you will get wrong answer. At first, I thought the link was wrong and I replaced it by the one we met during the course about Covid data in California. This act helps me to test the result on a python IDE but in fact it is the reason for the whole thing.
17th Mar 2021, 6:58 PM
Thoi Nhan NGO
Thoi Nhan NGO - avatar
+ 50
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"] max_ratio = df.loc[df["ratio"] == df["ratio"].max()] print(max_ratio)
23rd Mar 2021, 10:29 AM
Divya Sai lakshmi
Divya Sai lakshmi - avatar
+ 13
df['ratio'] = df['deaths'] / df['cases'] print (df['df['ratio'] == df['ratio'].max()]) Read the question carefully😁
17th Mar 2021, 4:51 PM
!Derrickee
!Derrickee - avatar
+ 6
""" sorry but why wouldn't this work? can someone explain? df['ratio'] = df['deaths'] / df['cases'] print (df['df['ratio'].max()]) """ Because df['ratio'].max() returns only max value of ratio so it looks like this: df[max_value_of_ratio] so it is mistake. When you want to get row from df you should equal it to the whole column. I did it with .loc method: df["ratio"] = df["deaths"] / df["cases"] max_ratio = df.loc[df["ratio"] == df["ratio"].max()] print(max_ratio)
23rd Mar 2021, 10:26 AM
Mirosław Topolski
Mirosław Topolski - avatar
+ 3
import pandas as pd df = pd.read_csv("/usercode/files/ca-covid.csv") df.set_index('date', inplace=True) df.drop('state', axis=1, inplace=True) print(df.iloc[-1])
4th Apr 2023, 6:07 PM
Francisca da Conceicao Boto
+ 1
df['ratio'] = df['deaths'] / df['cases'] print (df[df['ratio'] == df['ratio'].max()]) this work fine
11th Feb 2022, 9:55 PM
princeps ludwig
princeps ludwig - 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'] print(df[ df['ratio']==df['ratio'].max() ])
23rd Feb 2022, 7:33 PM
Issam Abdoh
Issam Abdoh - avatar
+ 1
I made it simple stupid and got a needed output print(df.iloc[-1])
5th Dec 2022, 9:04 PM
0yemets
0
sorry but why wouldn't this work? can someone explain? df['ratio'] = df['deaths'] / df['cases'] print (df['df['ratio'].max()])
23rd Mar 2021, 12:46 AM
Bruno
Bruno - avatar
0
Could anyone comment here what is the error here? 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) ratio=(deaths/cases)*100 df.insert('ratio') max_ratio=df.groupby('ratio')['ratio'].max() print(max_ratio)
4th Jun 2021, 1:05 AM
Kavuri Karthikeyan
0
print(df[df['ratio']==df['ratio'].max()]) works fine.
24th Nov 2021, 12:55 PM
Bilal Yoosuf
Bilal Yoosuf - avatar
0
!Derrickee remove " ' " before df in the print line that will bring syntax
11th Feb 2022, 9:54 PM
princeps ludwig
princeps ludwig - 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'] print(df.nlargest(1,'ratio'))
24th Oct 2022, 9:28 PM
Dawid Wojciechowski
Dawid Wojciechowski - avatar
0
its very simple you have to find the ratio ist df['ratio'] = df['deaths']/df['cases'] then find the max ratio and print it print(df[df['ratio'] == df['ratio'].max()])
30th Nov 2022, 1:38 PM
Shoaib Hayder
Shoaib Hayder - avatar
0
import numpy as np data = np.array([120, 98, 150, 65, 42, 100, 190, 220, 140, 110, 88, 89, 100, 120, 50, 180, 155, 42, 89, 77, 200, 190, 125, 98, 77, 40, 39, 59, 30, 67]) mean=np .mean(data) counter=0 for i in data: if i>mean: counter+=1 print(counter)
5th Dec 2022, 11:04 AM
Lavanya Mangala