Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Data Science by (50.2k points)

I have a dataframe like this:


I am calculation length of lists in the CreationDate column and making a new Length column like this:

df['Length'] = df.CreationDate.apply(lambda x: len(x))

Which gives me this:


Is there a more pythonic way to do this?

1 Answer

0 votes
by (108k points)

You can utilize the str accessor for some list operations as well. For instance:


returns the length of each list. Refer the following link for str.len:

If you wish to Learn more about Pandas visit this Pandas Tutorial.

Browse Categories