简体   繁体   English

使用 python 从 GCP 存储桶中递归读取所有子文件夹中的 csv 个文件

[英]Read csv files recursively in all sub folders from a GCP bucket using python

I was trying to load all csv files recursively from all sub folders available in a GCP bucket using python pandas.我试图使用 python pandas 从 GCP 存储桶中可用的所有子文件夹递归加载所有 csv 文件。

Currently I am using dask to load data, but its very slow.目前我正在使用dask加载数据,但速度很慢。

import dask
path = "gs://mybucket/parent_path + "*/*.csv"
getAllDaysData = dask.dataframe.read_csv(path).compute()

Can someone help me with better way.有人可以用更好的方法帮助我。

I would suggest reading into parquet files instead.我建议改为阅读镶木地板文件。 And use pd.read_parquet(file, engine = 'pyarrow') to convert it into a pandas dataframe.并使用pd.read_parquet(file, engine = 'pyarrow')将其转换为 pandas dataframe。

Alternatively you might want to consider loading data into BigQuery first.或者,您可能需要考虑先将数据加载到 BigQuery 中。 You can do something like this, as long as all csv-files have the some structure.只要所有 csv 文件都具有某种结构,您就可以这样做。

uri = f"gs://mybucket/parent_path/*.csv"
job_config = bigquery.LoadJobConfig(
    source_format=bigquery.SourceFormat.CSV
)

load_job = client.load_table_from_uri(
    uri,
    'destination_table',
    job_config=job_config,
    location=GCP_LOCATION
)
load_job_result = load_job.result()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 递归删除 S3 存储桶下的文件而不删除文件夹 - Delete files under S3 bucket recursively without deleting folders using python 如何使用 python 将文件夹从本地上传到 GCP 存储桶 - How to upload folder from local to GCP bucket using python 使用 PowerShell 递归删除 S3 存储桶下超过 30 天的文件而不删除文件夹 - Delete files older than 30 days under S3 bucket recursively without deleting folders using PowerShell 从 GCP 中的存储桶中读取图像用于 ML - Read images from a bucket in GCP for ML 如何使用 AWS SDK 为 Python 递归列出 AWS S3 存储桶中的文件? - How to recursively list files in AWS S3 bucket using AWS SDK for Python? 通过文件夹递归 go 并将每个文件夹中的 csv 个文件加载到 BigQuery 中 - Recursively go through folders and load the csv files in each folder into BigQuery 从 s3 存储桶中读取与 python 中的模式匹配的文件 - Read files from s3 bucket that match a pattern in python 如何使用 gcloud python 库或使用请求库列出所有 GCP 文件夹? - How to list all GCP folders by using gcloud python libraries or by using request library? 如何从 S3 存储桶中递归删除文件 - How to delete files recursively from an S3 bucket 仅列出 Cloud Function 存储桶 API 中 GCP GCS 中的顶级文件夹? - List only top level folders in GCP GCS from Cloud Function bucket API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM