Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Divide values from selected rows from one column by another column

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Preview of my output from the code above

>Solution :

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) 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading