keefxr
keefxr

Reputation: 13

How to find the length of a certain object in a data frame?

I am currently working with a data set of minecraft usernames:

0            ivixxw_18         4228398
1              slayne_         4228398
2            _megasik_         4228398
3               player         4228398
4            koteevski         4228398
...                ...             ...
4228393     _______ban         4228398
4228394  ________1_2_3         4228398
4228395  ________i___i         4228398
4228396      ________s         4228398
4228397     _________m         4228398

I want to create a column with the length of each user name without using a for loop. Is this possible? Right now I have

un['Length of Name'] = len(un)

This returns the length of the table (which makes sense to me, I just don't know how to fix it), not a specific row. How can I grab just one row?

Upvotes: 0

Views: 858

Answers (1)

jezrael
jezrael

Reputation: 862601

Use Series.str.len:

un['Length of Name'] = un['Name'].str.len()

Upvotes: 1

Related Questions