【发布时间】:2021-07-08 15:07:24
【问题描述】:
我正在使用 beam python SDK 使用 apache_beam.dataframe.io.read_csv 库读取两个 CSV 文件。
subscriber_data = (p | 'Read Subscriber File' >> read_csv('subscriber_data.csv'))
address_data = (p | 'Read address File' >> read_csv('address_data.csv'))
然后尝试使用以下代码使用 pd.merge left join 合并这些文件
subscriber_address_df = subscriber_data.merge(address_data.set_index('address_id').state,
right_index=True,
left_on='address_id',
how='left')
一旦我尝试使用以下代码打印subscriber_address_df
to_pcollection(subscriber_address_df , include_indexes=False) | beam.Map(print)
我收到了这个错误:
ValueError: Attempted to encode null for non-nullable field "state". [while running 'Unbatch 'merge_DataFrame_2137267343520'/ParDo(_UnbatchNoIndex)']
我该如何解决这个错误?
我的理解是,这个错误的发生是因为数据框架构中的非可空列状态的左连接产生了空值。
我尝试使用 to_pcollection 将数据帧切换到 Pcollection,并使用 .with_output_types 为该 pcollection 分配具有可为空列的架构,然后切换回数据帧 to_dataframe,但它不起作用
【问题讨论】:
标签: python apache-beam