2

have a df

a         b

mark     50

john     60

jack     30

harry     80

jacob     10

Need to make a new column in df with some random values

1 Answer 1

2

Create 2d random array of letters and join them in list comprehension:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.