Skip to content

Instantly share code, notes, and snippets.

@nackjicholson
Created December 13, 2016 00:38
Show Gist options
  • Save nackjicholson/c7a37230842f82fc51eaecf855fbf7ab to your computer and use it in GitHub Desktop.
Save nackjicholson/c7a37230842f82fc51eaecf855fbf7ab to your computer and use it in GitHub Desktop.
import yaml
import json
import pandas as pd
df = pd.DataFrame({'one': [1.0, 2.1, 3.2], 'two': [4.3, 5.4, 6.5]})
with open('df.yml', 'w') as file:
yaml.dump({'result': json.loads(df.to_json(orient='records'))}, file, default_flow_style=False)
@masonlr
Copy link

masonlr commented Aug 29, 2018

Is it possible to avoid the json dependency?

with open('df.yml', 'w') as file:
    yaml.dump({'result': df.to_dict(orient='records')}, file, default_flow_style=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment