具有df
a b
mark 50
john 60
jack 30
harry 80
jacob 10
需要在df中使用一些随机值创建新列
答案 0 :(得分:3)
创建2d个随机字母数组并将其加入列表理解:
L = list('abcdefghijklmnopqrstuvwxyz')
df['c'] = ['test'+ ''.join(x) for x in np.random.choice(L, size=(len(df), 3))]
print (df)
a b c
0 mark 50 testpje
1 john 60 testrmn
2 jack 30 testoud
3 harry 80 testasw
4 jacob 10 testagx