Reputation: 111
Input:df=
{
Name: "test",
Address: "xyz",
"Age": 40,
"Info": "test"
}
Output:
{
Name: "test",
Address: "xyz",
"Age": "40",
"Info": "test"
}
Note: I have tried json.dumps(df)
It is converting to string but numeric value i.e 40 in my example is not returning in double quote.
Any help or suggestions would be highly appreciated
Upvotes: 1
Views: 137
Reputation: 120409
If you dataframe looks like:
print(df)
# Output
Name Address Age Info
0 test xyz 40 test
1 test abc 20 test
and if you want to convert numeric values as string:
out = df.astype(str).to_json(orient='records', indent=4)
print(out)
# Output
[
{
"Name":"test",
"Address":"xyz",
"Age":"40",
"Info":"test"
},
{
"Name":"test",
"Address":"abc",
"Age":"20",
"Info":"test"
}
]
Upvotes: 1