Pandas, Filter By Count
I'm trying to filter a dataframe by the number of occurrences for
id date 1 2018-05-06 1 2018-05-08 1 2018-05-11 2 2018-06-02 2 2018-06-16 3 2018-06-04 3 2018-06-09 4 2018-06-06 4 2018-06-11 4 2018-06-17
I want to filter for the
id values that have 3 occurrences, so the resulting filtered dataframe should look like this:
id date 1 2018-05-06 1 2018-05-08 1 2018-05-11 4 2018-06-06 4 2018-06-11 4 2018-06-17
I previously had tried using the following code, which I got from another StackOverflow post. The code worked at first, but when I used it about a half hour later, it gave me the error "lambda cannot contain assignment":
graphview3 = df.groupby('id').filter(lambda x: x['id'].count()=3)
I don't know why this code previously worked and is now giving me this error. Any help on this?
graphview3 = df.loc[df['id'].map(df['id'].value_counts()) == 3]
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module