0 votes
1 view
in Data Science by (43.2k points)

I have a dataframe like this:

image

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:

image

Is there a more pythonic way to do this?

1 Answer

0 votes
by (92.8k points)

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

df['CreationDate'].str.len()

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

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.len.html

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...