imkanishks
imkanishks

Reputation: 11

Formatting of JSON file

Can we convert the highlighted INTEGER values to STRING value (refer below link)?

https://i.sstatic.net/3JbLQ.png

CODE

filename = "newsample2.csv"
jsonFileName = "myjson2.json"


import pandas as pd
df = pd.read_csv ('newsample2.csv')

df.to_json('myjson2.json', indent=4)
print(df)

Upvotes: 0

Views: 32

Answers (1)

George
George

Reputation: 151

Try doing something like this.

import pandas as pd

filename = "newsample2.csv"
jsonFileName = "myjson2.json"
df = pd.read_csv ('newsample2.csv')
df['index'] = df.index
df.to_json('myjson2.json', indent=4)
print(df)

This will take indices of your data and store them in the index column, so they will become a part of your data.

Upvotes: 1

Related Questions