我想使用 pandas 读取 .dta 数据集read_stata()
:
import pandas as pd
df=pd.read_stata('data_chunk1.dta')
但我收到关于解包缓冲区的错误:
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-5-8e0085ff8186> in <module>
----> 1 df=pd.read_stata('data_chunk10.dta')
2 df
~/anaconda3/lib/python3.8/site-packages/pandas/io/stata.py in read_stata(filepath_or_buffer, convert_dates, convert_categoricals, index_col, convert_missing, preserve_dtypes, columns, order_categoricals, chunksize, iterator)
1926
1927 try:
-> 1928 data = reader.read()
1929 finally:
1930 reader.close()
~/anaconda3/lib/python3.8/site-packages/pandas/io/stata.py in read(self, nrows, convert_dates, convert_categoricals, index_col, convert_missing, preserve_dtypes, columns, order_categoricals)
1616
1617 if convert_categoricals:
-> 1618 self._read_value_labels()
1619
1620 if len(data) == 0:
~/anaconda3/lib/python3.8/site-packages/pandas/io/stata.py in _read_value_labels(self)
1468 self.path_or_buf.read(3) # padding
1469
-> 1470 n = struct.unpack(self.byteorder + "I", self.path_or_buf.read(4))[0]
1471 txtlen = struct.unpack(self.byteorder + "I", self.path_or_buf.read(4))[0]
1472 off = np.frombuffer(
error: unpack requires a buffer of 4 bytes
我以前能够在 Google Collab 中读取这样的文件(因此问题不在于数据文件本身),但目前当我尝试在本地 PC 上运行代码时出现此错误。
你能告诉我我做错了什么吗?