{"id":1170878,"date":"2025-01-15T16:28:04","date_gmt":"2025-01-15T08:28:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1170878.html"},"modified":"2025-01-15T16:28:07","modified_gmt":"2025-01-15T08:28:07","slug":"python%e5%a6%82%e4%bd%95%e7%94%a8%e5%88%87%e7%89%87%e9%80%89%e5%8f%96%e5%88%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1170878.html","title":{"rendered":"python\u5982\u4f55\u7528\u5207\u7247\u9009\u53d6\u5217"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26073355\/93dc1d94-a3de-4e73-9546-87415ccec888.webp\" alt=\"python\u5982\u4f55\u7528\u5207\u7247\u9009\u53d6\u5217\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u4f7f\u7528\u5207\u7247\u9009\u53d6\u5217\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1aNumPy\u6570\u7ec4\u5207\u7247\u3001Pandas\u6570\u636e\u6846\u5207\u7247\u3001\u5217\u8868\u5207\u7247<\/strong>\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\uff0c<strong>NumPy\u548cPandas<\/strong>\u662f\u6700\u5e38\u7528\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u8fdb\u884c\u5217\u5207\u7247\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001NUMPY\u6570\u7ec4\u5207\u7247<\/h3>\n<\/p>\n<p><p>NumPy\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u503c\u8ba1\u7b97\u5e93\u4e4b\u4e00\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u7ec4\u5904\u7406\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528NumPy\u8fdb\u884c\u6570\u7ec4\u5207\u7247\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4\u3002\u4f60\u53ef\u4ee5\u4ece\u5217\u8868\u6216\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u521b\u5efa\u4e00\u4e2aNumPy\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a2x3\u7684NumPy\u6570\u7ec4<\/strong><\/h2>\n<p>arr = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<p>print(arr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[[1 2 3]<\/p>\n<p> [4 5 6]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u5207\u7247\u9009\u53d6\u5217<\/h4>\n<\/p>\n<p><p>\u8981\u4eceNumPy\u6570\u7ec4\u4e2d\u9009\u53d6\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u5192\u53f7\uff08:\uff09\u8fd0\u7b97\u7b26\u3002\u8fd9\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u7b2c1\u5217\uff08\u7d22\u5f15\u4ece0\u5f00\u59cb\uff09<\/p>\n<p>col1 = arr[:, 0]<\/p>\n<p>print(col1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[1 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<strong>arr[:, 0]<\/strong> \u8868\u793a\u9009\u53d6\u6240\u6709\u884c\u7684\u7b2c0\u5217\u3002\u7b2c\u4e00\u4e2a\u5192\u53f7\u8868\u793a\u6240\u6709\u884c\uff0c0\u8868\u793a\u5217\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u9009\u53d6\u591a\u5217<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5207\u7247\u9009\u53d6\u591a\u5217\u3002\u4f8b\u5982\uff0c\u9009\u53d6\u7b2c1\u5217\u548c\u7b2c2\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u7b2c1\u5217\u548c\u7b2c2\u5217<\/p>\n<p>cols_1_and_2 = arr[:, 0:2]<\/p>\n<p>print(cols_1_and_2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[[1 2]<\/p>\n<p> [4 5]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001PANDAS\u6570\u636e\u6846\u5207\u7247<\/h3>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u53e6\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u6846\uff08DataFrame\uff09\u5904\u7406\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528Pandas\u8fdb\u884c\u6570\u636e\u6846\u5217\u5207\u7247\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u4e00\u4e2aPandas\u6570\u636e\u6846<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aPandas\u6570\u636e\u6846\u3002\u4f60\u53ef\u4ee5\u4ece\u5b57\u5178\u3001\u5217\u8868\u6216\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u521b\u5efa\u4e00\u4e2aPandas\u6570\u636e\u6846\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aPandas\u6570\u636e\u6846<\/strong><\/h2>\n<p>data = {&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6], &#39;C&#39;: [7, 8, 9]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>   A  B  C<\/p>\n<p>0  1  4  7<\/p>\n<p>1  2  5  8<\/p>\n<p>2  3  6  9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u5217\u540d\u9009\u53d6\u5217<\/h4>\n<\/p>\n<p><p>\u5728Pandas\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5217\u540d\u76f4\u63a5\u9009\u53d6\u5217\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u5217A<\/p>\n<p>col_A = df[&#39;A&#39;]<\/p>\n<p>print(col_A)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>0    1<\/p>\n<p>1    2<\/p>\n<p>2    3<\/p>\n<p>Name: A, dtype: int64<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528iloc\u8fdb\u884c\u5207\u7247<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528iloc\u8fdb\u884c\u4f4d\u7f6e\u5207\u7247\u3002\u4f8b\u5982\uff0c\u9009\u53d6\u7b2c1\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u7b2c1\u5217<\/p>\n<p>col1 = df.iloc[:, 0]<\/p>\n<p>print(col1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>0    1<\/p>\n<p>1    2<\/p>\n<p>2    3<\/p>\n<p>Name: A, dtype: int64<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u9009\u53d6\u591a\u5217<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528iloc\u9009\u53d6\u591a\u5217\u3002\u4f8b\u5982\uff0c\u9009\u53d6\u7b2c1\u5217\u548c\u7b2c2\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u7b2c1\u5217\u548c\u7b2c2\u5217<\/p>\n<p>cols_1_and_2 = df.iloc[:, 0:2]<\/p>\n<p>print(cols_1_and_2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>   A  B<\/p>\n<p>0  1  4<\/p>\n<p>1  2  5<\/p>\n<p>2  3  6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5217\u8868\u5207\u7247<\/h3>\n<\/p>\n<p><p>\u9664\u4e86NumPy\u548cPandas\uff0c\u5982\u679c\u4f60\u53ea\u662f\u5904\u7406Python\u7684\u57fa\u672c\u5217\u8868\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u64cd\u4f5c\u6765\u9009\u53d6\u5217\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528\u5217\u8868\u5207\u7247\u7684\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u4e00\u4e2a\u5d4c\u5957\u5217\u8868<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5d4c\u5957\u5217\u8868\u3002\u5d4c\u5957\u5217\u8868\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5d4c\u5957\u5217\u8868<\/p>\n<p>lst = [[1, 2, 3], [4, 5, 6]]<\/p>\n<p>print(lst)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[[1, 2, 3], [4, 5, 6]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u9009\u53d6\u5217<\/h4>\n<\/p>\n<p><p>\u8981\u4ece\u5d4c\u5957\u5217\u8868\u4e2d\u9009\u53d6\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u7b2c1\u5217\uff08\u7d22\u5f15\u4ece0\u5f00\u59cb\uff09<\/p>\n<p>col1 = [row[0] for row in lst]<\/p>\n<p>print(col1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[1, 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u904d\u5386\u6bcf\u4e00\u884c\uff0c\u5e76\u9009\u53d6\u7b2c0\u5217\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u9009\u53d6\u591a\u5217<\/h4>\n<\/p>\n<p><p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u9009\u53d6\u591a\u5217\u3002\u4f8b\u5982\uff0c\u9009\u53d6\u7b2c1\u5217\u548c\u7b2c2\u5217\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9009\u53d6\u7b2c1\u5217\u548c\u7b2c2\u5217<\/p>\n<p>cols_1_and_2 = [[row[0], row[1]] for row in lst]<\/p>\n<p>print(cols_1_and_2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8f93\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code>[[1, 2], [4, 5]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7efc\u5408\u6bd4\u8f83<\/h3>\n<\/p>\n<p><h4>1\u3001\u6027\u80fd\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c<strong>NumPy\u548cPandas\u7684\u6027\u80fd\u4f18\u4e8e\u57fa\u672c\u5217\u8868\u64cd\u4f5c<\/strong>\u3002\u8fd9\u662f\u56e0\u4e3aNumPy\u548cPandas\u4f7f\u7528\u4e86\u5e95\u5c42\u7684C\u8bed\u8a00\u5b9e\u73b0\uff0c\u5177\u6709\u66f4\u9ad8\u7684\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u529f\u80fd\u6bd4\u8f83<\/h4>\n<\/p>\n<p><p><strong>Pandas\u63d0\u4f9b\u4e86\u66f4\u5f3a\u5927\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd<\/strong>\uff0c\u5982\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u900f\u89c6\u8868\u3001\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u7b49\u3002\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u590d\u6742\u7684\u6570\u636e\u5206\u6790\uff0cPandas\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5b9e\u9645\u5e94\u7528\u4e2d\u7684\u9009\u62e9<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u9700\u6c42\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u7b80\u5355\u6570\u636e\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u53ea\u662f\u8fdb\u884c\u7b80\u5355\u7684\u6570\u636e\u5904\u7406\uff0c\u57fa\u672c\u5217\u8868\u64cd\u4f5c\u5df2\u7ecf\u8db3\u591f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7b80\u5355\u6570\u636e\u5904\u7406\u793a\u4f8b<\/p>\n<p>lst = [[1, 2, 3], [4, 5, 6]]<\/p>\n<p>col1 = [row[0] for row in lst]<\/p>\n<p>print(col1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u503c\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u5927\u91cf\u7684\u6570\u503c\u8ba1\u7b97\uff0cNumPy\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u6570\u503c\u8ba1\u7b97\u793a\u4f8b<\/strong><\/h2>\n<p>arr = np.array([[1, 2, 3], [4, 5, 6]])<\/p>\n<p>col1 = arr[:, 0]<\/p>\n<p>print(col1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u6570\u636e\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u590d\u6742\u7684\u6570\u636e\u5206\u6790\uff0cPandas\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u6570\u636e\u5206\u6790\u793a\u4f8b<\/strong><\/h2>\n<p>data = {&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6], &#39;C&#39;: [7, 8, 9]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>col_A = df[&#39;A&#39;]<\/p>\n<p>print(col_A)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230Python\u4e2d\u4f7f\u7528\u5207\u7247\u9009\u53d6\u5217\u7684\u591a\u79cd\u65b9\u5f0f\u3002<strong>NumPy\u6570\u7ec4\u5207\u7247\u3001Pandas\u6570\u636e\u6846\u5207\u7247\u3001\u5217\u8868\u5207\u7247<\/strong>\u5404\u6709\u4f18\u52a3\uff0c\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u5177\u4f53\u7684\u9700\u6c42\u548c\u6570\u636e\u89c4\u6a21\u3002\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u548c\u590d\u6742\u6570\u636e\u5206\u6790\u65f6\uff0cNumPy\u548cPandas\u65e0\u7591\u662f\u66f4\u597d\u7684\u9009\u62e9\uff0c\u800c\u5728\u5904\u7406\u7b80\u5355\u6570\u636e\u65f6\uff0c\u5217\u8868\u5207\u7247\u4e5f\u662f\u4e00\u4e2a\u6709\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002\u5e0c\u671b\u901a\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u4f60\u80fd\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1Python\u4e2d\u4f7f\u7528\u5207\u7247\u9009\u53d6\u5217\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528\u5207\u7247\u9009\u62e9\u5217\u8868\u7684\u7279\u5b9a\u5217\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5207\u7247\u6765\u9009\u62e9\u5217\u8868\u4e2d\u7684\u7279\u5b9a\u5217\u3002\u4f8b\u5982\uff0c\u82e5\u6709\u4e00\u4e2a\u4e8c\u7ef4\u5217\u8868\uff08\u5217\u8868\u7684\u5217\u8868\uff09\uff0c\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a\u7d22\u5f15\u6765\u63d0\u53d6\u7279\u5b9a\u7684\u5217\u3002\u5047\u8bbe\u6709\u4e00\u4e2a\u6570\u636e\u7ed3\u6784\u5982 <code>data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/code>\uff0c\u8981\u63d0\u53d6\u7b2c\u4e8c\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u5b8c\u6210\uff1a<code>second_column = [row[1] for row in data]<\/code>\u3002\u8fd9\u6837\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u6240\u9700\u7684\u5217\u6570\u636e\u3002<\/p>\n<p><strong>\u5728NumPy\u4e2d\u5982\u4f55\u4f7f\u7528\u5207\u7247\u9009\u62e9\u6570\u7ec4\u7684\u5217\uff1f<\/strong><br \/>NumPy\u63d0\u4f9b\u4e86\u66f4\u4e3a\u5f3a\u5927\u7684\u5207\u7247\u529f\u80fd\uff0c\u4ee5\u4fbf\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u3002\u82e5\u4f7f\u7528NumPy\u5e93\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u6570\u7ec4 <code>arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7\u5207\u7247\u9009\u62e9\u7279\u5b9a\u7684\u5217\u3002\u4f8b\u5982\uff0c\u83b7\u53d6\u7b2c\u4e8c\u5217\u53ef\u4ee5\u4f7f\u7528 <code>arr[:, 1]<\/code>\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u4ec5\u7b80\u6d01\uff0c\u800c\u4e14\u6548\u7387\u9ad8\uff0c\u9002\u5408\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u6570\u636e\u6846\u4e2d\u5217\u7684\u9009\u62e9\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Pandas\u5e93\u65f6\uff0c\u6570\u636e\u6846\uff08DataFrame\uff09\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u65b9\u5f0f\u6765\u9009\u62e9\u5217\u3002\u5047\u8bbe\u6709\u4e00\u4e2a\u6570\u636e\u6846 <code>df<\/code>\uff0c\u8981\u9009\u62e9\u540d\u4e3a&#39;column_name&#39;\u7684\u5217\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 <code>df[&#39;column_name&#39;]<\/code>\u3002\u5982\u679c\u9700\u8981\u9009\u62e9\u591a\u4e2a\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868 <code>df[[&#39;column1&#39;, &#39;column2&#39;]]<\/code>\u3002Pandas\u7684\u7075\u6d3b\u6027\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u5904\u7406\u548c\u5206\u6790\u6570\u636e\uff0c\u9002\u5408\u5404\u79cd\u6570\u636e\u5904\u7406\u4efb\u52a1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u4f7f\u7528\u5207\u7247\u9009\u53d6\u5217\u7684\u4e3b\u8981\u65b9\u6cd5\u5305\u62ec\uff1aNumPy\u6570\u7ec4\u5207\u7247\u3001Pandas\u6570\u636e\u6846\u5207\u7247\u3001\u5217\u8868\u5207\u7247\u3002\u5728\u8fd9\u4e9b\u65b9\u6cd5\u4e2d [&hellip;]","protected":false},"author":3,"featured_media":1170883,"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\/1170878"}],"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=1170878"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1170878\/revisions"}],"predecessor-version":[{"id":1170884,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1170878\/revisions\/1170884"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1170883"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1170878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1170878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1170878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}