I cannot figure out what do the ask me to output | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
+ 2

# I cannot figure out what do the ask me to output

I guess I already solve the problem, but I just miss the correct value for ratio. This is what do they ask me to do... <<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. Important: The output should be a DataFrame, containing all of the columns of the dataset for the corresponding row.>> So my question is, how to calculate the ratio of the max values from cases and deaths?? You can access to the file by usisn this path in your code: /usercode/files/ca-covid.csv

6th Apr 2021, 8:33 PM
Bry4n
3 Réponses
+ 1
For your code all you need to do is add a new column 'ratio' to the dataframe df that is equal to the ratio of deaths per cases. (Divide deaths by cases). Then output the dataframe row where the ratio is equal to the max() for the dataframe. It only takes a couple lines of code. df['newColumnName'] = ratio_formula print(df[df['newColumnName'] == df['newColumnName'].max()])
6th Apr 2021, 8:57 PM
ChaoticDawg
+ 2
This is my code: ###### This is the given 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) ############################# # Looking for max value serie = df.describe() max = serie.loc['max'] ratio = {'cases':max['cases'], 'deaths':max['deaths']} df['ratio'] = ratio['cases'] - ratio['deaths'] dt = df.loc['26.12.20'] df_dict = { 'cases':dt['cases'], 'deaths':dt['deaths'], 'ratio':dt['ratio']} dt = pd.DataFrame(df_dict, index = ['26.12.20']) print(dt)
6th Apr 2021, 8:34 PM
Bry4n
+ 2
ChaoticDawg Thanks a lot, I really thank you, I was coding and coding tons of ideas but nothing works, and you come just with 2 lines and solve the whole of my problem 😂 so thanks again :D
6th Apr 2021, 9:59 PM
Bry4n
Aujourd'hui en vedette
Help Me!!!