簡體   English   中英

從zipfile中讀取sas7bdat作為熊貓數據框

[英]Reading sas7bdat as pandas dataframe from zipfile

我有一個名為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

您缺少參數format

import zipfile

zipfile = zipfile.ZipFile('myfile.zip', 'r')
sasfile = zipfile.open('mysasfile.sas7bdat')

df = pd.read_sas(sasfile, format='sas7bdat')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM