简体   繁体   English

如何使用 Python - Pandas 打开或将 SPSS (.sav) 文件转换为 CSV?

[英]How to open or convert SPSS (.sav) file into CSV using Python - Pandas?

I have .sav file and i need to convert it into csv file.我有 .sav 文件,我需要将其转换为 csv 文件。

I tried to use import savReaderWriter library but its not working.我尝试使用 import savReaderWriter库,但它不起作用。 I am getting this error:我收到此错误:

SPSSIOError: Problem opening file b'C:\\Users\\

I know in R it might be easier but i really need in Python.我知道在 R 中它可能更容易,但我真的需要在 Python 中。 Any help?有什么帮助吗?

Try with pyreadstat:尝试使用 pyreadstat:

import pyreadstat

df, meta = pyreadstat.read_sav(r"C:\path\to\file.sav")

df.to_csv("mycsv.csv")

You have to install it with :您必须使用以下命令安装它:

pip install pyreadstat

more information here:更多信息在这里:

https://github.com/Roche/pyreadstat https://github.com/Roche/pyreadstat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM