+ 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]])
11 Respostas
+ 6
print(df[df['ratio'] == df['ratio'].max()])
+ 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()
0
the link is not functional.
0
i editted @Wilbur Jaywright
0
df.loc[df.ratio.idxmax()]
df.idxmax() method returns the location of the maximum value.
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))
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()])
- 1
Thanks, with question and answer of Igor Kostrikin I found error in my code
- 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?
- 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])