如何从pyarrow的时间戳中获取“年”“月”“日期”?

时间:2021-02-24 09:30:19

标签: csv parquet pyarrow apache-arrow

我试图从箭头时间戳 [s] 类型中提取“年”“月”“日期”。我知道在pandas中怎么做,如下

import pyarrow.dataset as ds
dataset = ds.dataset(path, format="csv")
table = dataset.to_table()
## following codes wont work as table is arrow type and it doesn't have the map function.
table['date'] = table['time'].map(lambda t: pd.to_datetime(t, format="%Y-%m-%d %H:%M:%S"))
table['year'], table['month'], table['day'] = table['time'].apply(lambda x: x.year),table['date'].apply(lambda x: x.month), table['date'].apply(lambda x: x.day)

最简单的选择是将此箭头 DataFrame 转换为 Pandas 并执行此操作。但是我处理的文件大小很大,不想承担将其转换为熊猫的额外成本。由于最终目标是在获得年月日之后,我想将它们用作拼花地板的分区。

尽量避免中间转换,以提高将 csv 文件转换为 parquet 的效率。这是否可以通过箭头中的当前功能实现?

0 个答案:

没有答案