Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- tiny script to convert a pandas data frame into a JSON object
- """
- import json as json
- def df_to_json(df, filename=''):
- x = df.reset_index().T.to_dict().values()
- if filename:
- with open(filename, 'w+') as f: f.write(json.dumps(x))
- return x
Add Comment
Please, Sign In to add comment