{"kind":"task","effective_mode":"full","benchmark":{"kind":"benchmark","effective_mode":"full","slug":"ds-1000","formal_name":"DS-1000","introduction":"DS-1000 builds 1,000 data-science problems from real StackOverflow questions across seven libraries including NumPy, Pandas and Matplotlib. The problems are perturbed so that recalling the original answer does not solve them.","introduction_ja":"","introduction_en":"","category":"Category not supplied","task_count":null,"acquisition_status":"Acquisition status not supplied","official_url":"https://ds1000-code-gen.github.io/","indexing_mode":"index","profile":{"resources":[],"task_format":"","scoring":"","metric":"","size":"","answer_access":"","license":"","citation":"","maintainer":"","released":"","why_hard":"","related":[],"history":"","construction":"","limitations":"","saturation":"","scores":[]}},"task_id":"48d68028-fcda-5ad6-b8a7-8f2f5a32a4c6","task_key":"default--test--229","task_revision_id":"1","upstream_id":"229","short_description":"I have a DataFrame that looks like this:","config":"default","split":"test","body":"{\"library\":\"Pandas\",\"prompt\":\"Problem:\\nI have a DataFrame that looks like this:\\n\\n\\n+----------+---------+-------+\\n| username | post_id | views |\\n+----------+---------+-------+\\n| john | 1 | 3 |\\n| john | 2 | 23 |\\n| john | 3 | 44 |\\n| john | 4 | 82 |\\n| jane | 7 | 5 |\\n| jane | 8 | 25 |\\n| jane | 9 | 46 |\\n| jane | 10 | 56 |\\n+----------+---------+-------+\\nand I would like to transform it to count views that belong to certain bins like this:\\n\\nviews     (1, 10]  (10, 25]  (25, 50]  (50, 100]\\nusername\\njane            1         1         1          1\\njohn            1         1         1          1\\n\\nI tried:\\n\\n\\nbins = [1, 10, 25, 50, 100]\\ngroups = df.groupby(pd.cut(df.views, bins))\\ngroups.username.count()\\nBut it only gives aggregate counts and not counts by user. How can I get bin counts by user?\\n\\n\\nThe aggregate counts (using my real data) looks like this:\\n\\n\\nimpressions\\n(2500, 5000] 2332\\n(5000, 10000] 1118\\n(10000, 50000] 570\\n(50000, 10000000] 14\\nName: username, dtype: int64\\n\\nA:\\n<code>\\nimport pandas as pd\\n\\ndf = pd.DataFrame({'username': ['john', 'john', 'john', 'john', 'jane', 'jane', 'jane', 'jane'],\\n                   'post_id': [1, 2, 3, 4, 7, 8, 9, 10],\\n                   'views': [3, 23, 44, 82, 5, 25,46, 56]})\\nbins = [1, 10, 25, 50, 100]\\n</code>\\nresult = ... # put solution in this variable\\nBEGIN SOLUTION\\n<code>\\n\"}","display_format":"code","language":"","answer_status":"published","assets":[],"source_url":"https://ds1000-code-gen.github.io/","history":"initial import","indexing_mode":"index","subproblems":[],"grids":[]}