Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import pandas
  2. import json
  3. frame = pandas.DataFrame([{'one':1.0,'two':2.0},{'one':float('nan'),'two':3.0}])
  4.  
  5. # >>> frame
  6. # one two
  7. # 0 1.0 2.0
  8. # 1 NaN 3.0
  9.  
  10. # >>> frame.T.to_dict().values()
  11. # [{'two': 2.0, 'one': 1.0}, {'two': 3.0, 'one': nan}]
  12.  
  13. json_frame = json.dumps( frame.T.to_dict().values() )
  14.  
  15. # >>> json_frame
  16. # '[{"two": 2.0, "one": 1.0}, {"two": 3.0, "one": NaN}]'
  17.  
  18. json_frame = '[{"two": 2.0, "one": 1.0}, {"two": 3.0, "one": NaN}]'
  19. // "[{"two": 2.0, "one": 1.0}, {"two": 3.0, "one": NaN}]"
  20. JSON.parse(json_frame)
  21. // SyntaxError: Unexpected token N(…)
  22.  
  23. frame.where((pandas.notnull(frame)), None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement