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

Editing dataframe column values

My values in the totalGross column of the dataframe are as follows. I need to fix the values with [‘x’] expression because I need to find the equations.

df['totalNet'] = df['totalNet'].map(str)   

didn’t work for me.
Thanks.

input:

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

'totalNet': ["['385.88']",'385.88',"['188.93']",'188.93',"['342.66']",'342.66',"['178.52']",'178.52',"['1947.60']",'1947.60']

Output :

0           385.88
1           385.88
2           188.93
3           188.93
4           342.66

183         422.42
184         200.00
185         200.00
186        2461.77
187        2461.77

>Solution :

IIUC, you can use:

df['totalNet'] = pd.to_numeric(df['totalNet'].str.strip("'[]"), errors='coerce')

output:

0     385.88
1     385.88
2     188.93
3     188.93
4     342.66
5     342.66
6     178.52
7     178.52
8    1947.60
9    1947.60
Name: totalNet, dtype: float64
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