您如何使用 pyarrow for gcsfs 写入数据集?
我在使用 s3fs 时看到了一个类似的问题,似乎可行:Pyarrow s3fs partition by timetsamp
我试过
import os
import gcsfs
import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
data = {'date': ['2018-03-04T14:12:15.653Z', '2018-03-03T14:12:15.653Z', '2018-03-02T14:12:15.653Z', '2018-03-05T14:12:15.653Z'],
'battles': [34, 25, 26, 57],
'citys': ['london', 'newyork', 'boston', 'boston']}
df = pd.DataFrame(data, columns=['date', 'battles', 'citys'])
df['date'] = df['date'].map(lambda t: pd.to_datetime(t, format="%Y-%m-%dT%H:%M:%S.%fZ"))
df['year'], df['month'], df['day'] = df['date'].apply(lambda x: x.year), df['date'].apply(lambda x: x.month), df['date'].apply(lambda x: x.day)
df.groupby(by=['citys'])
gcs_bucket_name = '<my bucket name>'
GCP_Project_Name = '<my project name>'
fs_gcs = gcsfs.GCSFileSystem(project=GCP_Project_Name,token='browser')
table = pa.Table.from_pandas(df)
pq.write_to_dataset(table, 'gcs://test_bucket_python/dataset_name', filesystem=fs_gcs, partition_cols=['year', 'month', 'day'],compression='snappy')
我明白了OSError: Unrecognized filesystem: <class 'gcsfs.core.GCSFileSystem'>
请注意,它fs_gcs.ls(test_bucket_python)
有效,所以我知道我已正确连接到存储桶