python - 使用 Pandas 抛出错误在 Python 中编写 UDF
问题描述
我们正在尝试用 Python 编写 Hive 的 UDF 来清理数据。我们尝试的 UDF 使用的是 Pandas,它正在抛出错误。
当我们尝试在没有 Pandas 的情况下使用另一个 python 代码时,它工作正常。请帮助理解问题。在下面提供 Pandas 代码:
我们已经尝试了 Pandas 的各种方式,但不幸的是没有运气。由于其他没有 Pandas 的 Python 代码运行良好,我们很困惑为什么它会失败?
import sys
import pandas as pd
import numpy as np
for line in sys.stdin:
df = line.split('\t')
df1 = pd.DataFrame(df)
df2=df1.T
df2[0] = np.where(df2[0].str.isalpha(), df2[0], np.nan)
df2[1] = np.where(df2[1].astype(str).str.isdigit(), df2[1], np.nan)
df2[2] = np.where(df2[2].astype(str).str.len() != 10, np.nan,
df2[2].astype(str))
#df2[3] = np.where(df2[3].astype(str).str.isdigit(), df2[3], np.nan)
df2 = df2.dropna()
print(df2)
我收到此错误:
FAILED: Execution Error, return code 20003 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask. An error occurred when trying to close the Operator running your custom script.
MapReduce Jobs Launched:
Stage-Stage-1: Map: 1 HDFS Read: 0 HDFS Write: 0 FAIL
Total MapReduce CPU Time Spent: 0 msec
解决方案
I think you'll need to look at the detailed job logs for more information. My first guess is that Pandas is not installed on a data node.
This answer looks appropriate for you if you intend to bundle dependencies with your job: https://stackoverflow.com/a/2869974/7379644
推荐阅读
- java - 在使用 JaCoCo 插件配置分析 Maven 插件后,SonarQube 服务器上缺少 JaCoCo 代码覆盖率报告
- amazon-web-services - 如何知道 AWS Comprehend 的工作已经完成?
- php - 随机化帖子网址
- ruby - 如何使用带有可变长度参数列表的 if-else 语句?
- reactjs - 在 React 中引用导出
- reactjs - 如何确保在获取数据之前成功更新数据
- c# - AC# 数据结构,用于保存具有不同于“key”和“value”的标识符的 KeyValue 对
- c# - MVC View Viewmodel HttpPost 返回 NULL
- python - 在 Pandas 中透视包含重复条目的表
- java - 尝试使用 JPA 删除数据库中的 2 行。一个对象是从 id 创建的,但另一个不是