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

Convert csv to xpt format #25

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

Convert csv to xpt format #25

sbjain opened this issue Jan 28, 2019 · 2 comments

Comments

@sbjain
Copy link

sbjain commented Jan 28, 2019

Hi is there a function to convert csv to xpt? (Reverse of listed xpt to csv file)

Thanks,
Sagar

@meyergt
Copy link

meyergt commented Apr 30, 2019

Read the .csv into a dataframe:

df = pd.read_csv('file.csv')

Convert the dataframe to a list of dictionaries to then write to .xpt:

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

Write the list of dictionaries to .xpt:

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

@selik
Copy link
Owner

selik commented Apr 21, 2020

I've updated the README.

@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