我正在尝试将关系传递给Pig中的Python UDF。但它给我一个错误。以下是我的Pig Latin Script,Python Script和错误日志,
REGISTER '/home/cloudera/jython-installer-2.7.0.jar';
REGISTER '/home/cloudera/Code.py' USING jython as myfunc;
A = LOAD '/home/cloudera/Link.txt' as (line:chararray);
B = FOREACH A GENERATE myfunc.codefunc(line);
// Python脚本
import pandas as pd
def count(A, crime):
with open(A, 'r', encoding='UTF8') as fileA:
data = fileA.read().lower()
count = data.count(crime.lower())
return count
def codefunc(A):
crime = ['Rape', 'Murder', 'Extortion', 'Felony', 'Burglary', 'Property Damage', 'Arrest', 'Political Unrest', 'Civil Unrest', 'Solitication', 'Larceny', 'Abettor', 'Trafficking', 'Tresspasser', 'Robbery']
crimecount = {}
for i in range(len(crime)):
crimecount[crime[i]] = count(A, crime[i])
final_count = pd.DataFrame(list(crimecount.items()), columns = ['Crime', 'Value'])
final_count['Percentage'] = 0
total_count = final_count['Values'].sum()
for i in range(0, final_count.last_valid_index()+1):
final_count['Percentage'][i] = float((final_count['Values'][i]/total_count)*100.0)
final_count.sort_values(by=['Percentage'], ascending=False)
final_count.to_csv('/home/cloudera/solution.csv', header=0)
//错误日志 Link of Error Log
我已经放置了数据集所在的链接,并且我已经将Pig的链接传递给了Python。 Python应该转到该链接并读取数据集并执行编写的代码。 Python代码绝对没问题。我对此充满信心。但猪在关系中给我一个错误,' B'。我尝试在这里放置错误代码,但Stack Overflow不允许我这样做,所以我放置了链接。遗憾给您带来不便。谁能帮帮我吗。提前谢谢。
答案 0 :(得分:1)
你的代码绝对没问题。问题出在Jython上。 Jython不支持Pandas数据帧,因为它是用C / C ++编写的。所以振作起来!
希望你喜欢我的回答! YIPPEE !!