{"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":"noindex","profile":{"resources":[],"task_format":"","scoring":"","metric":"","size":"","answer_access":"","license":"","citation":"","maintainer":"","released":"","why_hard":"","related":[]}},"task_id":"50c8c7f9-01c5-5879-bcd3-844323df0bb6","task_key":"default--test--69","task_revision_id":"2","upstream_id":"69","short_description":"I'm wondering if there is a simpler, memory efficient way to select a subset of…","config":"default","split":"test","body":"{\"prompt\":\"Problem:\\nI'm wondering if there is a simpler, memory efficient way to select a subset of rows and columns from a pandas DataFrame.\\n\\n\\nFor instance, given this dataframe:\\n\\n\\n\\n\\ndf = DataFrame(np.random.rand(4,5), columns = list('abcde'))\\nprint df\\n          a         b         c         d         e\\n0  0.945686  0.000710  0.909158  0.892892  0.326670\\n1  0.919359  0.667057  0.462478  0.008204  0.473096\\n2  0.976163  0.621712  0.208423  0.980471  0.048334\\n3  0.459039  0.788318  0.309892  0.100539  0.753992\\nI want only those rows in which the value for column 'c' is greater than 0.45, but I only need columns 'a', 'b' and 'e' for those rows.\\n\\n\\nThis is the method that I've come up with - perhaps there is a better \\\"pandas\\\" way?\\n\\n\\n\\n\\nlocs = [df.columns.get_loc(_) for _ in ['a', 'b', 'e']]\\nprint df[df.c > 0.45][locs]\\n          a         b         e\\n0  0.945686  0.000710  0.326670\\n1  0.919359  0.667057  0.473096\\nMy final goal is to convert the result to a numpy array to pass into an sklearn regression algorithm, so I will use the code above like this:\\n\\n\\n\\n\\ntraining_set = array(df[df.c > 0.45][locs])\\n... and that peeves me since I end up with a huge array copy in memory. Perhaps there's a better way for that too?\\n\\nA:\\n<code>\\nimport pandas as pd\\nimport numpy as np\\n\\ndf = pd.DataFrame(np.random.rand(4,5), columns = list('abcde'))\\ncolumns = ['a','b','e']\\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":"noindex","subproblems":[],"grids":[]}