如何在pyspark中创建一个随机字符串的新列



我试图用随机字符串添加一个新列到我的数据框,我如何使randomword的输出符合withColumn的输入


def randomword(length):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(length))
df_with_new_col = mydf.withColumn('random_string', randomword(10))
''.join(random.choices(string.ascii_lowercase, k=N))

random.choicesPython 3.6+

最新更新