{"action":"created","issue":{"url":"https://api.github.com/repos/gpuopenanalytics/pygdf/issues/171","repository_url":"https://api.github.com/repos/gpuopenanalytics/pygdf","labels_url":"https://api.github.com/repos/gpuopenanalytics/pygdf/issues/171/labels{/name}","comments_url":"https://api.github.com/repos/gpuopenanalytics/pygdf/issues/171/comments","events_url":"https://api.github.com/repos/gpuopenanalytics/pygdf/issues/171/events","html_url":"https://github.com/gpuopenanalytics/pygdf/issues/171","id":345367714,"node_id":"MDU6SXNzdWUzNDUzNjc3MTQ=","number":171,"title":"Inconsistent values while using .applyrows()","user":{"login":"Nanthini10","id":11373237,"node_id":"MDQ6VXNlcjExMzczMjM3","avatar_url":"https://avatars1.githubusercontent.com/u/11373237?v=4","gravatar_id":"","url":"https://api.github.com/users/Nanthini10","html_url":"https://github.com/Nanthini10","followers_url":"https://api.github.com/users/Nanthini10/followers","following_url":"https://api.github.com/users/Nanthini10/following{/other_user}","gists_url":"https://api.github.com/users/Nanthini10/gists{/gist_id}","starred_url":"https://api.github.com/users/Nanthini10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nanthini10/subscriptions","organizations_url":"https://api.github.com/users/Nanthini10/orgs","repos_url":"https://api.github.com/users/Nanthini10/repos","events_url":"https://api.github.com/users/Nanthini10/events{/privacy}","received_events_url":"https://api.github.com/users/Nanthini10/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-27T21:11:54Z","updated_at":"2018-08-02T15:02:37Z","closed_at":null,"author_association":"NONE","body":"Trying to convert string(category) into numerical values. The equivalent of applying `.to_numeric()` in pandas\r\n```\r\ndf_left = pd.DataFrame()\r\nnelem = 5\r\ndf_left['key1'] = np.random.randint(0, 3, nelem)\r\ndf_left['key2'] = np.random.randint(0, 5, nelem)\r\ndf_left['val1'] = ['1', '2', '5', '3', '2']\r\ndf_left['val1'] = df_left['val1'].astype('category')\r\ndf_left = DataFrame.from_pandas(df_left)\r\n\r\ndf_left\r\n```\r\n\r\n```\r\n  key1 key2 val1\r\n0    2    0    1\r\n1    0    4    2\r\n2    1    3    5\r\n3    1    4    3\r\n4    0    4    2\r\n```\r\n```\r\ndef kernel(val1, out1, extra1):\r\n    for i, val in enumerate(val1):\r\n        out1[i] = int(val)\r\n\r\nval1 = df_left['val1']\r\noutdf = df_left.apply_rows(kernel, incols=['val1'], \r\n                           outcols=dict(out1=np.int64), kwargs=dict(extra1=1))\r\noutdf\r\n```\r\n```\r\n  key1 key2 val1 out1\r\n0    2    0    1    0\r\n1    0    4    2    1\r\n2    1    3    5    3\r\n3    1    4    3    2\r\n4    0    4    2    1\r\n```\r\n\r\n`outdf['out1']` should be exactly same as `val1` but be of the type `int`\r\n\r\nPandas equivalent:\r\n```\r\ndf = pd.DataFrame()\r\nnelem = 5\r\ndf['key1'] = np.random.randint(0, 3, nelem)\r\ndf['key2'] = np.random.randint(0, 5, nelem)\r\ndf['val1'] = ['1', '2', '5', '3', '2']\r\ndf['val1'] = df['val1'].astype('category')\r\ndf['out1'] = pd.to_numeric(df['val1'])\r\ndf\r\n```\r\n```\r\n\r\nkey1\tkey2\tval1\tout1\r\n0\t1\t0\t1\t1\r\n1\t1\t1\t2\t2\r\n2\t0\t2\t5\t5\r\n3\t2\t3\t3\t3\r\n4\t2\t0\t2\t2\r\n```"},"comment":{"url":"https://api.github.com/repos/gpuopenanalytics/pygdf/issues/comments/409958409","html_url":"https://github.com/gpuopenanalytics/pygdf/issues/171#issuecomment-409958409","issue_url":"https://api.github.com/repos/gpuopenanalytics/pygdf/issues/171","id":409958409,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTk1ODQwOQ==","user":{"login":"Nanthini10","id":11373237,"node_id":"MDQ6VXNlcjExMzczMjM3","avatar_url":"https://avatars1.githubusercontent.com/u/11373237?v=4","gravatar_id":"","url":"https://api.github.com/users/Nanthini10","html_url":"https://github.com/Nanthini10","followers_url":"https://api.github.com/users/Nanthini10/followers","following_url":"https://api.github.com/users/Nanthini10/following{/other_user}","gists_url":"https://api.github.com/users/Nanthini10/gists{/gist_id}","starred_url":"https://api.github.com/users/Nanthini10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nanthini10/subscriptions","organizations_url":"https://api.github.com/users/Nanthini10/orgs","repos_url":"https://api.github.com/users/Nanthini10/repos","events_url":"https://api.github.com/users/Nanthini10/events{/privacy}","received_events_url":"https://api.github.com/users/Nanthini10/received_events","type":"User","site_admin":false},"created_at":"2018-08-02T15:02:37Z","updated_at":"2018-08-02T15:02:37Z","author_association":"NONE","body":"Yes, `df['val1'].cat.codes` values match the output out the kernel. "}}
{"actor":{"display_login":"Nanthini10"}}