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

Formatting a dataframe in Pandas

I got a dataframe looking like this:

       A    B    C 
0      1    2    3
1      2    2    1

I want to send the values from the dataframe into a HTTP POST where the format looks like this:

"1,2,3",
"2,2,1",

How is it possible to format the output from the dataframe to be able to achieve desired output?

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 convert values to strings if need join them:

L = df.astype(str).agg(','.join, 1).tolist()
print (L)
['1,2,3', '2,2,1']

For json output convert list:

import json

j = json.dumps(L)
print (j)
["1,2,3", "2,2,1"]
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