Santhosh reddy
Santhosh reddy

Reputation: 111

Not able to change json value of number to double quote

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

Answers (1)

Corralien
Corralien

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

Related Questions