Home > Mobile >  Formatting a dataframe in Pandas
Formatting a dataframe in Pandas

Time:12-16

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?

CodePudding user response:

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"]
  • Related