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

Problem to replace a strange string need some advise

I was transforming my object data to float and int and I found this error:

ValueError: invalid literal for int() with base 10: '[24]'

from what I understand the [] are like strings and I’m having trouble removing them and leaving just the number, how do I do that? I tried to replace but when I put ‘[]’ as a character to replace, it understands as a list, I want to remove [] to leave only the number,

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 try .str.strip

df['out'] = df['col'].str.strip('[]')
print(df)

    col out
0  [23]  23
1  [23]  23
2  [23]  23
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