我有一个名为myfile.zip
的zip文件,其中包含文件mysasfile.sas7bdat
,我想将其作为熊猫数据框读取。我已经尝试了一些无效的方法,但这是我目前的方法:
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
答案 0 :(得分:0)
您缺少参数format
import zipfile
zipfile = zipfile.ZipFile('myfile.zip', 'r')
sasfile = zipfile.open('mysasfile.sas7bdat')
df = pd.read_sas(sasfile, format='sas7bdat')