【发布时间】:2020-01-17 15:01:10
【问题描述】:
我是 Apache Beam 的新手,刚开始使用 Python SDK 进行开发。 关于 Apache Beam,我知道高级别的 Pipelines、Pcollections、Ptransforms、ParDo 和 DoFn。
在我当前的项目管道中,已经使用 PANDAS 实现了使用下面提到的语法来读取、转换和写入文件
我想了解这是否是 Apache Beam 的正确实现,因为我们仅使用 PANDAS 直接读取和写入文件,而不是逐个元素地处理文件。
步骤:
- 创建管道
- 创建输入文件路径的 pcollection
- 调用DoFn并传递文件路径
- 使用 PANDAS 在 DoFn 中执行所有操作(读取、转换和写入)。
示例高级代码:
import **required libraries
class ActionClass(beam.DoFn):
def process(self, file_path):
#reading file using PANDAS into dataframe
df = pandas.read_csv('file_path')
# do some transformation using pandas
#write dataframe to output file from inside DoFn only.
return
def run():
p = beam.Pipeline(options=options)
input = p | beam.io.ReadFromText('input_file_path') --reading only file path
output = input | 'PTransform' | beam.ParDo(ActionClass)
【问题讨论】:
标签: python pandas apache-beam