I am trying to divide values from the 'total_deaths' column by the values from the 'total_cases' column from rows 0 to 634 and I want the result to show as a new column named 'CFR'.
This is what I have tried, but it divided all the values in both columns instead of only rows 0 to 634.
data['CFR'] = np.round(data['total_deaths']/data['total_cases']*100,3)
CodePudding user response:
Use the loc accessor. Code below
data.loc[0:634,'CFR'] = np.round(data.loc[0:634,'total_deaths']/data.loc[0:634,'total_cases']*100,3)