I have a list of years in a pandas data frame. I want to filter them using a lambda function, which I am trying to pass using count method. For me, using lambda is the most convenient way, I would prefer a solution that involves lambda.
print df['year_built'][:5]
print df['year_built'].count(lambda x: len(x) == 4)
0 1981
1 1980
2 1935
3 2007
4 1994
Name: year_built, dtype: object
AttributeError: 'RangeIndex' object has no attribute 'levels'
What is the optimal way to do this using lambda and without it?
countdoesn't even take a callable object. Are you trying to count the number of elements of length 4?