【发布时间】:2021-09-12 14:19:54
【问题描述】:
我正在尝试使用 Pyspark 重写我的 Python 脚本 (Pandas),但我找不到一种方法来应用我的 Pandas 函数以提高 Pyspark 函数的效率:
我的功能如下:
def decompose_id(id_flight):
my_id=id_flight.split("_")
Esn=my_id[0]
Year=my_id[3][0:4]
Month=my_id[3][4:6]
return Esn, Year, Month
def reverse_string(string):
stringlength=len(string) # calculate length of the list
slicedString=string[stringlength::-1] # slicing
return slicedString
我想将第一个函数应用于数据框的一列(在 Pandas 中,我得到一行三个元素) 第二个函数用于验证 DataFrame 列的条件时使用
有没有使用 Pyspark 数据框应用它们的方法?
【问题讨论】:
-
Pandas 和 Spark 的工作方式不同。请用示例输入和输出解释您想要做什么。忘记你的 pandas 函数,解释预期的行为。
-
顺便说一句,
reverse_string应该只是def reverse_string(string):return string[::-1]。而string是内置库的名称,最好使用另一个词,例如in_string。 -
感谢您的评论!
标签: python pandas pyspark bigdata user-defined-functions