{"id":195067,"date":"2020-07-08T10:00:37","date_gmt":"2020-07-08T02:00:37","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=195067"},"modified":"2020-06-28T08:57:22","modified_gmt":"2020-06-28T00:57:22","slug":"python-linux-inplace","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/python-linux-inplace.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdPython drop\u65b9\u6cd5\u5220\u9664\u5217\u4e4binplace\u53c2\u6570\u5b9e\u4f8b"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Python drop\u65b9\u6cd5\u5220\u9664\u5217\u4e4binplace\u53c2\u6570\u5b9e\u4f8b\uff0c\u5177\u6709\u5f88\u597d\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002\u4e00\u8d77\u8ddf\u968f\u5c0f\u7f16\u8fc7\u6765\u770b\u770b\u5427<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n drop\u65b9\u6cd5\u6709\u4e00\u4e2a\u53ef\u9009\u53c2\u6570inplace\uff0c\u8868\u660e\u53ef\u5bf9\u539f\u6570\u7ec4\u4f5c\u51fa\u4fee\u6539\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u6570\u7ec4\u3002\u4e0d\u7ba1\u53c2\u6570\u9ed8\u8ba4\u4e3aFalse\u8fd8\u662f\u8bbe\u7f6e\u4e3aTrue\uff0c\u539f\u6570\u7ec4\u7684\u5185\u5b58\u503c\u662f\u4e0d\u4f1a\u6539\u53d8\u7684\uff0c\u533a\u522b\u5728\u4e8e\u539f\u6570\u7ec4\u7684\u5185\u5bb9\u662f\u5426\u76f4\u63a5\u88ab\u4fee\u6539\u3002\u9ed8\u8ba4\u4e3aFalse,\u8868\u660e\u539f\u6570\u7ec4\u5185\u5bb9\u5e76\u4e0d\u6539\u53d8\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u5f97\u5230\u6539\u53d8\u540e\u7684\u5185\u5bb9\uff0c\u9700\u8981\u5c06\u65b0\u7ed3\u679c\u8d4b\u7ed9\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4\uff0c\u5373data = data.drop(['test','test2'],1)\u3002<\/p>\n \u5982\u679c\u5c06inplace\u503c\u8bbe\u5b9a\u4e3aTrue,\u5219\u539f\u6570\u7ec4\u5185\u5bb9\u76f4\u63a5\u88ab\u6539\u53d8\u3002<\/p>\n \u6d4b\u8bd5\u7a0b\u5e8f\u5982\u4e0b<\/p>\n \r\n#\u589e\u52a0\u4e24\u5217\u7a7a\u503c\r\nimport numpy as np\r\ndata[\"test\"] = np.nan\r\ndata[\"test2\"] = np.nan\r\n \r\nname gender age test2 test\r\n0 jerry M 36 NaN NaN\r\n1 emma F 23 NaN NaN\r\n2 tony M 34 NaN NaN\r\n4 bob M 20 NaN NaN\r\n \r\n#\u67e5\u770b\u6b64\u65f6data\u7684\u5185\u5b58\u5730\u5740\r\nid(data)\r\n128971088\r\n \r\n#\u5220\u9664\u8fd9\u4e24\u5217\uff0cinplace\u9ed8\u8ba4\u4e3aFalse\r\nid(data.drop(['test','test2'],1))\r\n128971888\r\n \r\n#\u67e5\u770bdata,\u53d1\u73b0\u6570\u636e\u5e76\u672a\u6539\u53d8\r\ndata\r\nname gender age test test2\r\n0 jerry M 36 NaN NaN\r\n1 emma F 23 NaN NaN\r\n2 tony M 34 NaN NaN\r\n4 bob M 20 NaN NaN\r\n \r\n#\u67e5\u770bdata\u7684ID\r\nid(data)\r\n128971088\r\n \r\n#\u5220\u9664\u8fd9\u4e24\u5217\uff0cinplace\u8bbe\u7f6e\u4e3aFalse\r\nid(data.drop(['test','test2'],1,inplace = True))\r\n1545984728\r\n \r\n#\u67e5\u770bdata,\u6570\u636e\u5df2\u7ecf\u6539\u53d8\r\ndata\r\nname gender age test test2\r\n0 jerry M 36 NaN NaN\r\n1 emma F 23 NaN NaN\r\n2 tony M 34 NaN NaN\r\n4 bob M 20 NaN NaN\r\n \r\n#\u67e5\u770bdata\u7684ID\r\nid(data)\r\n128971088<\/pre>\n |