i have actually a pandas dataframe and i want to save it to json format. From the pandas docs it says:
Note NaN‘s, NaT‘s and None will be converted to null and datetime objects will be converted based on the date_format and date_unit parameters
Then using the orient option records i have something like this
[{"A":1,"B":4,"C":7},{"A":null,"B":5,"C":null},{"A":3,"B":null,"C":null}]
Is it possible to have this instead:
[{"A":1,"B":4,"C":7},{"B":5},{"A":3}]'
Thank you
dropnathe nulls before writing the JSON? - KatrielNaNvalues, or to parse the json dict and strip the entries out, I don't think dfs will allow a form where the dimensions are different for each row. Thinking about it you could create a dict for each row that doesn't contain the NaN values and then callto_jsonon that column, let me try this - EdChumdf.apply(lambda x: [x.dropna()], axis=1).to_json()gets close to what you want? - EdChum