我试图用随机字符串添加一个新列到我的数据框,我如何使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.choices
Python 3.6+