Guest User

Untitled

a guest
Apr 27th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. """
  2. tiny script to convert a pandas data frame into a JSON object
  3. """
  4.  
  5. import json as json
  6.  
  7. def df_to_json(df, filename=''):
  8. x = df.reset_index().T.to_dict().values()
  9. if filename:
  10. with open(filename, 'w+') as f: f.write(json.dumps(x))
  11. return x
Add Comment
Please, Sign In to add comment