{"id":985370,"date":"2024-12-27T07:36:05","date_gmt":"2024-12-26T23:36:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/985370.html"},"modified":"2024-12-27T07:36:07","modified_gmt":"2024-12-26T23:36:07","slug":"python-%e5%a6%82%e4%bd%95%e7%9c%8b%e8%a1%8c%e7%bb%b4%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/985370.html","title":{"rendered":"python \u5982\u4f55\u770b\u884c\u7ef4\u5ea6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212552\/27ee4691-bb8d-44ed-8aa2-ff28607312b3.webp\" alt=\"python \u5982\u4f55\u770b\u884c\u7ef4\u5ea6\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u770b\u884c\u7ef4\u5ea6\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pandas\u5e93\u4e2d\u7684DataFrame\u5bf9\u8c61\u3001\u5229\u7528NumPy\u6570\u7ec4\u7684shape\u5c5e\u6027\u3001\u4ee5\u53ca\u76f4\u63a5\u5bf9\u5217\u8868\u8fdb\u884c\u8fed\u4ee3\u7b49\u3002pandas\u5e93\u662f\u5904\u7406\u6570\u636e\u7684\u5e38\u7528\u5de5\u5177\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u65b9\u4fbf\u7684\u65b9\u6cd5\u6765\u67e5\u770b\u548c\u64cd\u4f5c\u6570\u636e\u7684\u7ef4\u5ea6\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u67e5\u770b\u6570\u636e\u7684\u884c\u7ef4\u5ea6\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u3002\u884c\u7ef4\u5ea6\u4e0d\u4ec5\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\u6570\u636e\u96c6\u7684\u5927\u5c0f\uff0c\u8fd8\u5bf9\u8fdb\u4e00\u6b65\u7684\u6570\u636e\u64cd\u4f5c\u63d0\u4f9b\u4e86\u57fa\u7840\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u884c\u7ef4\u5ea6\u7684\u65b9\u6cd5\uff0c\u4ee5\u53ca\u5982\u4f55\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5229\u7528\u8fd9\u4e9b\u65b9\u6cd5\u8fdb\u884c\u6570\u636e\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528PANDAS\u67e5\u770b\u884c\u7ef4\u5ea6<\/h2>\n<\/p>\n<p><p>pandas\u662fPython\u4e2d\u5904\u7406\u6570\u636e\u7684\u5f3a\u5927\u5e93\u4e4b\u4e00\uff0c\u5b83\u80fd\u591f\u9ad8\u6548\u5730\u5904\u7406\u548c\u5206\u6790\u5927\u578b\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528DataFrame\u7684shape\u5c5e\u6027<\/h3>\n<\/p>\n<p><p>pandas\u4e2d\u7684DataFrame\u5bf9\u8c61\u662f\u5904\u7406\u8868\u683c\u6570\u636e\u7684\u6838\u5fc3\u6570\u636e\u7ed3\u6784\u3002\u8981\u67e5\u770bDataFrame\u7684\u884c\u7ef4\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528shape\u5c5e\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684DataFrame<\/strong><\/h2>\n<p>data = {&#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>        &#39;Age&#39;: [25, 30, 35]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u83b7\u53d6DataFrame\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>rows, columns = df.shape<\/p>\n<p>print(f&quot;\u884c\u7ef4\u5ea6: {rows}, \u5217\u7ef4\u5ea6: {columns}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>df.shape<\/code>\u6765\u83b7\u53d6DataFrame\u7684\u884c\u548c\u5217\u7684\u6570\u91cf\u3002shape\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u4e24\u4e2a\u5143\u7d20\u7684\u5143\u7ec4\uff0c\u5206\u522b\u8868\u793a\u884c\u548c\u5217\u7684\u6570\u91cf\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528len\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u867d\u7136shape\u5c5e\u6027\u662f\u67e5\u770bDataFrame\u884c\u7ef4\u5ea6\u7684\u6700\u76f4\u63a5\u65b9\u6cd5\uff0c\u4f46\u4f7f\u7528len\u51fd\u6570\u4e5f\u80fd\u8fbe\u5230\u76f8\u540c\u7684\u6548\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">num_rows = len(df)<\/p>\n<p>print(f&quot;\u884c\u7ef4\u5ea6: {num_rows}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>len\u51fd\u6570\u8fd4\u56deDataFrame\u7684\u884c\u6570\uff0c\u8fd9\u5728\u9700\u8981\u5feb\u901f\u67e5\u770b\u884c\u6570\u91cf\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528NUMPY\u67e5\u770b\u884c\u7ef4\u5ea6<\/h2>\n<\/p>\n<p><p>NumPy\u662f\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u8ba1\u7b97\u7684\u57fa\u7840\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528\u6570\u7ec4\u7684shape\u5c5e\u6027<\/h3>\n<\/p>\n<p><p>NumPy\u6570\u7ec4\u4e5f\u6709shape\u5c5e\u6027\uff0c\u53ef\u4ee5\u7528\u6765\u67e5\u770b\u6570\u7ec4\u7684\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684NumPy\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/p>\n<h2><strong>\u83b7\u53d6\u6570\u7ec4\u7684\u5f62\u72b6<\/strong><\/h2>\n<p>rows, columns = array.shape<\/p>\n<p>print(f&quot;\u884c\u7ef4\u5ea6: {rows}, \u5217\u7ef4\u5ea6: {columns}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0epandas\u7684DataFrame\u7c7b\u4f3c\uff0cNumPy\u6570\u7ec4\u7684shape\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6570\u7ec4\u884c\u548c\u5217\u6570\u91cf\u7684\u5143\u7ec4\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u7ed3\u5408\u5176\u4ed6\u65b9\u6cd5\u67e5\u770b<\/h3>\n<\/p>\n<p><p>NumPy\u6570\u7ec4\u53ef\u4ee5\u4e0e\u5176\u4ed6\u65b9\u6cd5\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u66f4\u7075\u6d3b\u5730\u67e5\u770b\u884c\u7ef4\u5ea6\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5207\u7247\u64cd\u4f5c\u6765\u9009\u62e9\u7279\u5b9a\u7684\u884c\u6216\u5217\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7279\u5b9a\u884c\u7684\u6570\u91cf<\/p>\n<p>specific_rows = array[:2]  # \u9009\u62e9\u524d\u4e24\u884c<\/p>\n<p>num_specific_rows = specific_rows.shape[0]<\/p>\n<p>print(f&quot;\u7279\u5b9a\u884c\u7ef4\u5ea6: {num_specific_rows}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u67e5\u770b\u7279\u5b9a\u884c\u6216\u5b50\u6570\u7ec4\u7684\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u76f4\u63a5\u64cd\u4f5c\u5217\u8868\u67e5\u770b\u884c\u7ef4\u5ea6<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5217\u8868\u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7ed3\u6784\u4e4b\u4e00\u3002\u867d\u7136\u5217\u8868\u6ca1\u6709\u4e13\u95e8\u7684shape\u5c5e\u6027\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5176\u4ed6\u65b9\u6cd5\u6765\u786e\u5b9a\u5176\u884c\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5d4c\u5957\u5217\u8868\u7684\u884c\u7ef4\u5ea6<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5d4c\u5957\u5217\u8868\uff08\u5373\u5217\u8868\u4e2d\u7684\u5143\u7d20\u4e5f\u662f\u5217\u8868\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7len\u51fd\u6570\u6765\u786e\u5b9a\u5176\u884c\u7ef4\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">nested_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/p>\n<h2><strong>\u83b7\u53d6\u5d4c\u5957\u5217\u8868\u7684\u884c\u7ef4\u5ea6<\/strong><\/h2>\n<p>num_rows = len(nested_list)<\/p>\n<p>print(f&quot;\u884c\u7ef4\u5ea6: {num_rows}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0clen\u51fd\u6570\u8fd4\u56de\u5d4c\u5957\u5217\u8868\u4e2d\u7684\u5143\u7d20\u6570\u91cf\uff0c\u5373\u884c\u7684\u6570\u91cf\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u9010\u884c\u8fed\u4ee3\u67e5\u770b<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u9010\u884c\u67e5\u770b\u5217\u8868\u4e2d\u7684\u6570\u636e\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u7684for\u5faa\u73af\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for index, row in enumerate(nested_list):<\/p>\n<p>    print(f&quot;\u884c {index + 1}: {row}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u80fd\u67e5\u770b\u884c\u6570\uff0c\u8fd8\u80fd\u8bbf\u95ee\u6bcf\u4e00\u884c\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u4f7f\u7528<\/h2>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\uff0c\u67e5\u770b\u884c\u7ef4\u5ea6\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u63a2\u8ba8\u5982\u4f55\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u5229\u7528\u8fd9\u4e9b\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u6570\u636e\u6e05\u6d17\u4e0e\u9884\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u6e05\u6d17\u8fc7\u7a0b\u4e2d\uff0c\u4e86\u89e3\u6570\u636e\u7684\u884c\u7ef4\u5ea6\u6709\u52a9\u4e8e\u8bc6\u522b\u7f3a\u5931\u503c\u3001\u91cd\u590d\u6570\u636e\u548c\u5f02\u5e38\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5904\u7406\u7f3a\u5931\u503c<\/p>\n<p>df.dropna(inplace=True)<\/p>\n<h2><strong>\u79fb\u9664\u91cd\u590d\u884c<\/strong><\/h2>\n<p>df.drop_duplicates(inplace=True)<\/p>\n<h2><strong>\u786e\u8ba4\u6e05\u6d17\u540e\u7684\u884c\u7ef4\u5ea6<\/strong><\/h2>\n<p>cleaned_rows = df.shape[0]<\/p>\n<p>print(f&quot;\u6e05\u6d17\u540e\u7684\u884c\u7ef4\u5ea6: {cleaned_rows}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u7279\u5f81\u5de5\u7a0b<\/h3>\n<\/p>\n<p><p>\u5728\u7279\u5f81\u5de5\u7a0b\u9636\u6bb5\uff0c\u884c\u7ef4\u5ea6\u7684\u53d8\u5316\u901a\u5e38\u662f\u7279\u5f81\u751f\u6210\u548c\u9009\u62e9\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6dfb\u52a0\u65b0\u7279\u5f81<\/p>\n<p>df[&#39;AgeGroup&#39;] = pd.cut(df[&#39;Age&#39;], bins=[0, 18, 35, 60], labels=[&#39;Young&#39;, &#39;Adult&#39;, &#39;Senior&#39;])<\/p>\n<h2><strong>\u786e\u8ba4\u7279\u5f81\u5de5\u7a0b\u540e\u7684\u884c\u7ef4\u5ea6<\/strong><\/h2>\n<p>engineered_rows = df.shape[0]<\/p>\n<p>print(f&quot;\u7279\u5f81\u5de5\u7a0b\u540e\u7684\u884c\u7ef4\u5ea6: {engineered_rows}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u7279\u5f81\u5de5\u7a0b\u4e2d\uff0c\u884c\u7ef4\u5ea6\u7684\u53d8\u5316\u53ef\u80fd\u6307\u793a\u6570\u636e\u5904\u7406\u4e2d\u7684\u9519\u8bef\u6216\u4e0d\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u6a21\u578b\u8bad\u7ec3\u4e0e\u9a8c\u8bc1<\/h3>\n<\/p>\n<p><p>\u5728\u673a\u5668\u5b66\u4e60\u6a21\u578b\u8bad\u7ec3\u4e2d\uff0c\u884c\u7ef4\u5ea6\u76f4\u63a5\u5f71\u54cd\u6a21\u578b\u7684\u8f93\u5165\u5927\u5c0f\u3002\u56e0\u6b64\uff0c\u5728\u5206\u5272\u6570\u636e\u96c6\u65f6\uff0c\u67e5\u770b\u884c\u7ef4\u5ea6\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.model_selection import tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n_test_split<\/p>\n<h2><strong>\u5206\u5272\u6570\u636e\u96c6<\/strong><\/h2>\n<p>train_set, test_set = train_test_split(df, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u67e5\u770b\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u7684\u884c\u7ef4\u5ea6<\/strong><\/h2>\n<p>train_rows = train_set.shape[0]<\/p>\n<p>test_rows = test_set.shape[0]<\/p>\n<p>print(f&quot;\u8bad\u7ec3\u96c6\u884c\u7ef4\u5ea6: {train_rows}, \u6d4b\u8bd5\u96c6\u884c\u7ef4\u5ea6: {test_rows}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u4fdd\u8bad\u7ec3\u96c6\u548c\u6d4b\u8bd5\u96c6\u7684\u6bd4\u4f8b\u5408\u9002\uff0c\u5e76\u4e14\u6570\u636e\u5206\u5272\u8fc7\u7a0b\u6b63\u786e\u65e0\u8bef\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u603b\u7ed3\u4e0e\u5efa\u8bae<\/h2>\n<\/p>\n<p><p>\u67e5\u770b\u884c\u7ef4\u5ea6\u662f\u6570\u636e\u5206\u6790\u3001\u9884\u5904\u7406\u548c\u5efa\u6a21\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u65e0\u8bba\u662f\u4f7f\u7528pandas\u3001NumPy\u8fd8\u662f\u76f4\u63a5\u64cd\u4f5c\u5217\u8868\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u4f18\u52bf\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u6570\u636e\u5206\u6790\u9879\u76ee\u65f6\uff0c\u5efa\u8bae\u9996\u5148\u4e86\u89e3\u6570\u636e\u96c6\u7684\u57fa\u672c\u7ed3\u6784\uff0c\u5305\u62ec\u884c\u7ef4\u5ea6\u548c\u5217\u7ef4\u5ea6\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u66f4\u597d\u5730\u89c4\u5212\u6570\u636e\u64cd\u4f5c\u6d41\u7a0b\uff0c\u786e\u4fdd\u6570\u636e\u5904\u7406\u7684\u6bcf\u4e00\u6b65\u90fd\u7ecf\u8fc7\u4ed4\u7ec6\u9a8c\u8bc1\u548c\u68c0\u67e5\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u5e0c\u671b\u60a8\u80fd\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u884c\u7ef4\u5ea6\uff0c\u5e76\u5728\u60a8\u7684\u6570\u636e\u5206\u6790\u5de5\u4f5c\u4e2d\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u6280\u5de7\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u770b\u6570\u636e\u7684\u884c\u6570\u548c\u5217\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u901a\u5e38\u4f7f\u7528Pandas\u5e93\u6765\u5904\u7406\u6570\u636e\u3002\u53ef\u4ee5\u4f7f\u7528<code>DataFrame.shape<\/code>\u5c5e\u6027\u6765\u83b7\u53d6\u6570\u636e\u7684\u884c\u6570\u548c\u5217\u6570\u3002<code>shape<\/code>\u8fd4\u56de\u4e00\u4e2a\u5143\u7ec4\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f\u884c\u6570\uff0c\u7b2c\u4e8c\u4e2a\u5143\u7d20\u662f\u5217\u6570\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = pd.read_csv(&#39;your_file.csv&#39;)  # \u66ff\u6362\u4e3a\u4f60\u7684\u6587\u4ef6\u540d\nprint(data.shape)  # \u8f93\u51fa\u884c\u6570\u548c\u5217\u6570\n<\/code><\/pre>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u8bfb\u53d6\u5e76\u663e\u793a\u7279\u5b9a\u884c\u7684\u6570\u636e\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u4e2d\u7684<code>.iloc[]<\/code>\u65b9\u6cd5\u6765\u9009\u62e9\u7279\u5b9a\u7684\u884c\u3002\u901a\u8fc7\u7d22\u5f15\u53ef\u4ee5\u83b7\u53d6\u5355\u884c\u6216\u591a\u884c\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c<code>data.iloc[0]<\/code>\u5c06\u8fd4\u56de\u7b2c\u4e00\u884c\u6570\u636e\uff0c\u800c<code>data.iloc[0:5]<\/code>\u5c06\u8fd4\u56de\u524d\u4e94\u884c\u6570\u636e\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">specific_row = data.iloc[0]  # \u83b7\u53d6\u7b2c\u4e00\u884c\nprint(specific_row)\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u68c0\u67e5Python\u4e2d\u6570\u636e\u6846\u7684\u884c\u7ef4\u5ea6\u662f\u5426\u6709\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>isnull()<\/code>\u548c<code>sum()<\/code>\u65b9\u6cd5\u6765\u68c0\u67e5\u6570\u636e\u6846\u4e2d\u7684\u7f3a\u5931\u503c\u3002\u901a\u8fc7<code>data.isnull().sum()<\/code>\u53ef\u4ee5\u5f97\u5230\u6bcf\u4e00\u5217\u7684\u7f3a\u5931\u503c\u6570\u91cf\uff0c\u4ece\u800c\u5e2e\u52a9\u5224\u65ad\u884c\u7ef4\u5ea6\u7684\u5b8c\u6574\u6027\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">missing_values = data.isnull().sum()  # \u8ba1\u7b97\u6bcf\u5217\u7684\u7f3a\u5931\u503c\nprint(missing_values)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u770b\u884c\u7ef4\u5ea6\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528pandas\u5e93\u4e2d\u7684DataFrame\u5bf9\u8c61\u3001\u5229\u7528NumPy\u6570\u7ec4\u7684shap [&hellip;]","protected":false},"author":3,"featured_media":985379,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985370"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=985370"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985370\/revisions"}],"predecessor-version":[{"id":985382,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/985370\/revisions\/985382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/985379"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=985370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=985370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=985370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}