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 separate list elements with comma in pandas

I have this dataframe:

d = {'col1': [1, 2,3,4,5], 'col2': [6,7,8,9,10]}
df = pd.DataFrame(data=d)
print(df)

which looks like this:

   col1  col2
0     1     6
1     2     7
2     3     8
3     4     9
4     5    10

I then transform the col1 into a list:

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

a = df['col1'].values
print(a)

which looks like this:

[1 2 3 4 5]

I’d like to get the elements in list a to look like this:

[1,2,3,4,5]

How can I do that in pandas?

>Solution :

Just make it a list 🙂

list(df['col1'])
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