简体   繁体   English

使用 Apache Beam (Python) 解压缩文件,但在使用 WriteToText 时,它将所有列作为行

[英]Unzipping files with Apache Beam (Python) but when using WriteToText it puts all columns as lines

I am very new to programming and Apache Beam, and I am trying to read plenty zip files on aa GCS bucket and unzip them and save again as csv on GCS.我对编程和 Apache Beam 非常陌生,我正在尝试在 GCS 存储桶上读取大量 zip 文件并将它们解压缩并再次保存为 GCS 上的 csv。

with beam.Pipeline() as pipeline:
readable_files = (
  pipeline
  | beam.io.fileio.MatchFiles('path/file/patter*.zip')
  | beam.io.fileio.ReadMatches()
  | beam.FlatMap(unzip)
  | beam.combiners.ToList())
files_and_contents = (
  readable_files  
  | beam.io.WriteToText('new', file_name_suffix='.csv'))

An I am unzipping the files with this function我正在使用此功能解压缩文件

def unzip(readable_file):
print(readable_file)
input_zip=zipfile.ZipFile(readable_file.open())
yield {name: input_zip.read(name) for name in input_zip.namelist()}

I have tested it with two files only, and all lines were written as columns, here is an example.我仅用两个文件对其进行了测试,并且所有行都写为列,这是一个示例。 The header is a column, and all the other lines columns.标题是一列,所有其他行都是列。

CSV file saved已保存 CSV 文件

在 beam.io.file io.ReadMatches() 内尝试添加 skip_header_lines=1

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

相关问题 Python Apache 光束 WriteToText 设置零件文件的最大大小 - Python Apache beam WriteToText setting max size for part files 使用python解压缩大文件 - unzipping large files using python 使用 Apache Beam 将文件写入 Parquet 中的动态目标 Python SDK - Writing files to dynamic destinations in Parquet using Apache Beam Python SDK 使用Python解压缩文件时的性能问题 - Performance issue in unzipping files using Python 使用Python迭代解压缩文件数 - Unzipping number of files iteratively by using Python 使用for循环时,通过Python SDK在Apache Beam中编写循环PTransform。所有循环都使用迭代器的最后一个值 - When using for loop, to write looping PTransform in Apache Beam by Python SDK. All loops use the last value of a iterator 有没有办法读取除python apache beam中定义的文件列表之外的所有文件? - Is there a way to read all files excluding a defined list of files in python apache beam? Python 解压文件 - Unzipping files in Python 如何使用 Apache 光束(Python)在 Bigquery 中将列从一个表连接到另一个数据流 - How to join columns from one table to another in Bigquery using Apache beam (Python) for a dataflow 在 GCP 数据流上使用 python apache 光束中的 scipy - Using scipy in python apache beam on GCP Dataflow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM