1

I'd like to convert a data frame into a json file. One of the columns of the data frame contains time series as a string. Thus, the final json looks like this:

[{"...":"...","Dauer":"24h","Wertereihe":"8619.0,9130.0,8302.0,8140.0"}, {...}, {...}]

Is it possible to save the df to a json file in such a way that "Wertereihe" is an array of numbers? This would give: [{"...":"...","Dauer":"24h","Wertereihe":[8619.0,9130.0,8302.0,8140.0]}, {...}, {...}]

I used the following snippet to save the df to a json file: df.to_json(jsonFile, orient = "records")

SkogensKonung
  • 601
  • 1
  • 9
  • 22

1 Answers1

2

IIUC, you need:

df['Wertereihe'] = df['Wertereihe'].apply(lambda x: list(map(float, x.split(','))))
df.to_json(jsonFile, orient = "records")
Muhammad Hassan
  • 4,079
  • 1
  • 13
  • 27