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

how to move the +- errors estimates to another column with pandas

so i have a pandas dataframe that looks like this :

enter image description here

is there a way to move the errors in Ep and Sbolo to two other column without having to do it by hand? thank you

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

>Solution :

You can use str.split:

df[['sb1', 'sb2']] = (df['S Bolo'].str.split('\s*\u00b1\s*', expand=True)
                                  .apply(pd.to_numeric, errors='coerce'))
print(df)

# Output
         S Bolo    sb1   sb2
0  17.90 ± 0.13  17.90  0.13
1   4.43 ± 0.08   4.43  0.08

The unicode value of ± is U+00B1 and do the same for other column.

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