I have a Pandas GroupBy Data frame named ratings_by_title that looks like the following:
title
$1,000,000 Duck (1971) 37
'Night Mother (1986) 70
'Til There Was You (1997) 52
'burbs, The (1989) 303
...And Justice for All (1979) 199
1-900 (1994) 2
10 Things I Hate About You (1999) 700
101 Dalmatians (1961) 565
101 Dalmatians (1996) 364
12 Angry Men (1957) 616
I am trying to filter out the titles having a rating of >=250 so,
I tried the following active_titles = ratings_by_title.index[ratings_by_title >= 250]
But,This gives an error in iPython saying
AttributeError: Cannot access attribute 'index' of 'DataFrameGroupBy' objects, try using the 'apply' method
Could somebody help me understand what's going on?
Got it ... when grouping by should add the size method
eg) ratings_by_title = data.groupby('title').size()
This solved the issue!!
Now i can index like:
active_ratings = ratings_by_title.index[ratings_by_title >= 250]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With