3

Currently I am generating unique uuid in each row using loop like this -

df['uuid'] = df.apply(lambda x: uuid.uuid4(), axis=1)

Is there way to do this without loop?

1 Answer 1

5

Remains a loop, but is a little faster than the current way

df['uuid'] = [uuid.uuid4() for x in range(df.shape[0])]

24.4 µs ± 2.31 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

Using apply

df['uuid'] = df.apply(lambda x: uuid.uuid4(), axis=1)

1.25 ms ± 39.1 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.