Skip to content
Advertisement

Create multiple columns at once based off of existing columns

I have this dataframe df:

JavaScript

I want to create two new columns at once which are simply the character length of the existing two columns. The result should look like this:

JavaScript

I’ve tried to use for comprehension to generate the lists at once, such as so:

JavaScript

but I get

JavaScript

I would like to do more complex operations and create lots of new columns from pre-existing columns as such, and do not want to manually create each new column one at a time. Any help is appreciated!

Advertisement

Answer

No need to use apply, .str.len() should work:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement