我正在使用 pandas/dask 进行计算,并将我的数据存储在磁盘上的 parquet 文件中。问题是,我有一个“时间”列,还有一个称为时间的索引。我想保留两者。当我存储数据然后稍后加载时,我收到以下错误:
import pyarrow as pa
import pyarrow.parquet as pq
%matplotlib inline
dfx.to_dict()
Out[115]:
{'close': {Timestamp('2017-06-30 01:31:00'): 154.99958999999998,
Timestamp('2017-06-30 01:32:00'): 154.99958999999998,
Timestamp('2017-06-30 01:33:00'): 154.01109,
Timestamp('2017-06-30 01:34:00'): 154.01109,
Timestamp('2017-06-30 01:35:00'): 152.60051000000001},
'time': {Timestamp('2017-06-30 01:31:00'): Timestamp('2017-06-30 01:31:00'),
Timestamp('2017-06-30 01:32:00'): Timestamp('2017-06-30 01:32:00'),
Timestamp('2017-06-30 01:33:00'): Timestamp('2017-06-30 01:33:00'),
Timestamp('2017-06-30 01:34:00'): Timestamp('2017-06-30 01:34:00'),
Timestamp('2017-06-30 01:35:00'): Timestamp('2017-06-30 01:35:00')}}
# set index column
dfx.set_index('time', drop=False, inplace=True)
dfx.head()
Out[117]:
time close
time
2017-06-30 01:31:00 2017-06-30 01:31:00 154.99959
2017-06-30 01:32:00 2017-06-30 01:32:00 154.99959
2017-06-30 01:33:00 2017-06-30 01:33:00 154.01109
2017-06-30 01:34:00 2017-06-30 01:34:00 154.01109
2017-06-30 01:35:00 2017-06-30 01:35:00 152.60051
# store to parquet file format
tdfx = pa.Table.from_pandas(dfx)
pq.write_table(tdfx, 'data.parquet' )
# recovering
dfx = pq.read_table('data.parquet').to_pandas()
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-119-5e9d7cd2ea0d> in <module>()
1 # recovering
----> 2 dfx = pq.read_table('data.parquet').to_pandas()
pyarrow/table.pxi in pyarrow.lib.Table.to_pandas (/arrow/python/build/temp.linux-x86_64-3.6/lib.cxx:37990)()
/home/ghildebrand/anaconda3/envs/p36/lib/python3.6/site-packages/pyarrow/pandas_compat.py in table_to_blockmanager(options, table, memory_pool, nthreads)
296 i = schema.get_field_index(name)
297 if i != -1:
--> 298 col = table.column(i)
299 index_name = (None if is_unnamed_index_level(name)
300 else name)
pyarrow/table.pxi in pyarrow.lib.Table.column (/arrow/python/build/temp.linux-x86_64-3.6/lib.cxx:38622)()
IndexError: Table column index 2 is out of range
这是pyarrow中的一个错误,还是镶木地板不可能做到这一点,还是我做错了什么?
更新:删除冗余列“时间”并仅保留索引解决。所以我想问题是在镶木地板的某个地方创建了唯一的列标识符集。