【发布时间】:2019-05-22 10:38:53
【问题描述】:
我尝试在 python 中用熊猫 concat() 两个 parquet 文件。
它可以工作,但是当我尝试将数据框写入并保存到镶木地板文件时,它会显示错误:
ArrowInvalid: Casting from timestamp[ns] to timestamp[ms] would lose data:
我检查了文档。 pandas,写入 parquet 文件时默认使用 ms 时间戳语法。
如何在 concat 之后使用已使用的模式将镶木地板文件变白?
这是我的代码:
import pandas as pd
table1 = pd.read_parquet(path= ('path.parquet'),engine='pyarrow')
table2 = pd.read_parquet(path= ('path.parquet'),engine='pyarrow')
table = pd.concat([table1, table2], ignore_index=True)
table.to_parquet('./file.gzip', compression='gzip')
【问题讨论】:
-
看来 parquet 只支持 ms 而 pandas 正在使用 ns。您是否尝试按照here 的建议使用
from_pandas和to_pandas? -
@hansaplast 你好,伙计,是的,我已经尝试过医生的建议。 ,但我认为导致它无法工作的原因是我用函数编写了错误的语法。 pd.Timestamp (np.datetime64[ns])
-
pandas 需要公开一些选项以允许不安全的强制转换或将 int96 纳秒时间戳写入 Parquet。你能打开一个关于熊猫的问题吗?
-
Pandas 将给予
to_parquet的大多数关键字转发给给定的引擎。这个问题尤其可以用table.to_parquet(allow_truncated_timestamps=True)解决