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

Convert a string with numbers into a list of integers using Python

I’ve a dataframe column with an string of numbers and I want to convert it into a list of numbers. The output must be a list, since I need be able to pull the index value (for instance, df.probabilities[0][0] and return 0.001).

This my current dataframe:

 probabilities
 0.001, 0.002, 0.003, 0.004

I need this:

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

  probabilities
  [0.001, 0.002, 0.003, 0.004]

Thank you in advance.

>Solution :

Uses .str accessor with split:

df['probabilities'].str.split(',\s?')
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