I realize that this may seem like a question that has already been asked here, but none of the solutions seem to work. I start out with a dictionary that looks something along the line of this:
{'2016-05-08': 1, '2016-05-09': nan, '2016-05-05': nan, '2016-05-06': nan, '2016-05-07': nan, '2016-05-11': nan, 'address': '<email address>, '2016-05-12': nan, '2016-05-10': nan}
I read this data into a pandas DataFrame, looking something like this:
address date1 date2 date3 date4 date5 date6 date7
<email> NaN NaN NaN 1 NaN NaN NaN
I then use the following methods to calculate the mean and standard deviation and add them to the DataFrame:
mean = pd.Series(df.mean(axis=1), index=df.index)
std = pd.Series(df.std(axis=1), index=df.index)
df = pd.concat([df, mean, std], axis=1)
When I print df
, it looks as it should. However, when I used this method to write the DataFrame to a JSON string, df.to_json(<path to file>)
, it get the original dictionary in my JSON file. I want a JSON string of all the data with the standard deviation and mean included in the JSON data, how can I do this?
Aucun commentaire:
Enregistrer un commentaire