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

15th Mar 2021, 9:39 AM
Mahsa Farahani
Mahsa Farahani - avatar
10 ответов
+ 6
print(df[df['ratio'] == df['ratio'].max()])
15th Mar 2021, 11:40 AM
Igor Kostrikin
Igor Kostrikin - avatar
+ 2
Line Plot Fill in the blanks to create a line chart for the COVID data showing the daily number of deaths in the month of June. df[df['month']==6]['deaths'].plot()
10th Nov 2021, 9:33 PM
Fayziev Damirjon Furkatovich
Fayziev Damirjon Furkatovich - avatar
0
the link is not functional.
15th Mar 2021, 10:58 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
i editted @Wilbur Jaywright
15th Mar 2021, 11:35 AM
Mahsa Farahani
Mahsa Farahani - avatar
0
df.loc[df.ratio.idxmax()] df.idxmax() method returns the location of the maximum value.
16th May 2021, 9:23 AM
Gbadegesin Muhammed
Gbadegesin Muhammed - avatar
0
import pandas as pd df = pd.read_csv("/usercode/files/ca-covid.csv") df.drop('state', axis=1, inplace=True) df['date'] = pd.to_datetime(df['date'], format="%d.%m.%y") df['weekday']=(df['date']).dt.strftime("%A") print(df.tail(7))
19th Sep 2022, 7:09 AM
ROTHSchild
0
This is what I ended up with doing it in the print statement thanks to help from Igor Kostrikin - huge help: 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) #create the ratio column and make it = to deaths/cases df['ratio']=df['deaths']/df['cases'] #print entire dataframe but show max ratio print(df[df['ratio'] == df['ratio'].max()])
22nd Mar 2023, 6:40 PM
Tina O'Connell
Tina O'Connell - avatar
- 1
Thanks, with question and answer of Igor Kostrikin I found error in my code
15th Mar 2021, 10:17 PM
Sergey Lavrov
Sergey Lavrov - avatar
- 1
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?
17th Mar 2021, 4:36 PM
Thoi Nhan NGO
Thoi Nhan NGO - avatar
- 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])
9th Jul 2021, 11:03 AM
DENİZ MUSTAFAOĞLU
DENİZ MUSTAFAOĞLU - avatar