【发布时间】:2019-08-28 04:17:09
【问题描述】:
我有一个名为 myfile.zip 的 zip 文件,其中包含一个文件 mysasfile.sas7bdat,我想将其读取为 pandas 数据框。我尝试了一些没有用的方法,但这是我目前的方法:
import zipfile
zipfile = zipfile.ZipFile('myfile.zip', 'r')
sasfile = zipfile.open('mysasfile.sas7bdat')
df = pd.read_sas(sasfile)
错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-82-6d55436287b5> in <module>()
3 imgfile = archive.open('curated_dataset_preview.sas7bdat')
4
----> 5 df = pd.read_sas(imgfile)
/opt/python/python35/lib/python3.5/site-packages/pandas/io/sas/sasreader.py in read_sas(filepath_or_buffer, format, index, encoding, chunksize, iterator)
38 filepath_or_buffer = _stringify_path(filepath_or_buffer)
39 if not isinstance(filepath_or_buffer, compat.string_types):
---> 40 raise ValueError(buffer_error_msg)
41 try:
42 fname = filepath_or_buffer.lower()
ValueError: If this is a buffer object rather than a string name, you must specify a format string
【问题讨论】:
标签: python python-3.x pandas sas