Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving new df as xpt file #24

Closed
sbjain opened this issue Jan 20, 2019 · 2 comments
Closed

Saving new df as xpt file #24

sbjain opened this issue Jan 20, 2019 · 2 comments

Comments

@sbjain
Copy link

sbjain commented Jan 20, 2019

Hi, can you explain how we can save the dataframe (df) to new xpt file?

Thanks,
Sagar

@meyergt
Copy link

meyergt commented Apr 30, 2019

I do it using this line to convert it to a list of dictionaries:

data = df.T.to_dict().values()

And then these two lines to write the .xpt file:

with open('file.xpt', 'wb') as f:
    xport.from_rows(data, f)

@selik
Copy link
Owner

selik commented Apr 21, 2020

New API. #34

In [1]: import pandas as pd

In [2]: import xport.v56

In [3]: df = pd.DataFrame()

In [4]: with open('example.xpt', 'wb') as f:
   ...:     xport.v56.dump(df, f)
   ...:

However, it'll be best if you use the xport.Dataset to set metadata for your dataset.

@selik selik closed this as completed Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants