Reputation: 546
Basically, pandas can copy the column by
df['B'] = df['A'] + 1
Now, I have a column of strings and I want to add a column whose values are the lengths of each string. For example,
A. B
"hello" 5
"hi" 2
Is it possible to add B without looping?
Upvotes: 1
Views: 417
Reputation: 168
You can use apply
to get the length of column
df['B'] = df['A'].apply(len)
A. B
"hello" 5
"hi" 2
Upvotes: 0