{"id":1128322,"date":"2025-01-08T20:19:19","date_gmt":"2025-01-08T12:19:19","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1128322.html"},"modified":"2025-01-08T20:19:23","modified_gmt":"2025-01-08T12:19:23","slug":"python%e5%a6%82%e4%bd%95%e8%af%bb%e5%8f%96%e7%9f%a9%e9%98%b5%e4%b8%ad%e6%9f%90%e4%b8%aa%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1128322.html","title":{"rendered":"python\u5982\u4f55\u8bfb\u53d6\u77e9\u9635\u4e2d\u67d0\u4e2a\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25095057\/4b9c188b-1896-4b5d-9e34-4c430359e8dc.webp\" alt=\"python\u5982\u4f55\u8bfb\u53d6\u77e9\u9635\u4e2d\u67d0\u4e2a\u6570\u636e\u7c7b\u578b\" \/><\/p>\n<p><p> <strong>Python\u8bfb\u53d6\u77e9\u9635\u4e2d\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u51e0\u79cd\u65b9\u6cd5<\/strong>\u5305\u62ec\uff1a<strong>\u4f7f\u7528NumPy\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528Pandas\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528\u5185\u7f6e\u5217\u8868\u8bfb\u53d6\u77e9\u9635<\/strong>\u7b49\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u6cd5\u5728Python\u4e2d\u8bfb\u53d6\u77e9\u9635\u4e2d\u7279\u5b9a\u7684\u6570\u636e\u7c7b\u578b\uff0c\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528NumPy\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528NumPy\u8bfb\u53d6\u77e9\u9635<\/h3>\n<\/p>\n<p><p>NumPy\u662fPython\u4e2d\u5904\u7406\u77e9\u9635\u548c\u6570\u7ec4\u7684\u5f3a\u5927\u5e93\uff0c\u5176\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u51fd\u6570\u548c\u65b9\u6cd5\u6765\u65b9\u4fbf\u5730\u64cd\u4f5c\u6570\u7ec4\u548c\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5\u548c\u5bfc\u5165NumPy<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86NumPy\u5e93\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165NumPy\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u548c\u8bfb\u53d6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528NumPy\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\u975e\u5e38\u7b80\u5355\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=np.int32)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u8bfb\u53d6\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix[1, 2]  # \u8bfb\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u8bfb\u53d6\u77e9\u9635\u4e2d\u7279\u5b9a\u7684\u6570\u636e\u7c7b\u578b\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u77e9\u9635<\/p>\n<p>matrix = np.array([[1.5, 2.3, 3.1], [4.2, 5.5, 6.8], [7.9, 8.6, 9.4]])<\/p>\n<h2><strong>\u8bfb\u53d6\u6240\u6709\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>float_elements = matrix[matrix.dtype == np.float64]<\/p>\n<p>print(float_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Pandas\u8bfb\u53d6\u77e9\u9635<\/h3>\n<\/p>\n<p><p>Pandas\u662f\u53e6\u4e00\u79cd\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u7279\u522b\u9002\u7528\u4e8e\u5904\u7406\u8868\u683c\u6570\u636e\u3002Pandas\u63d0\u4f9b\u4e86DataFrame\u5bf9\u8c61\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8bfb\u53d6\u548c\u64cd\u4f5c\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5\u548c\u5bfc\u5165Pandas<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u5b89\u88c5Pandas\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165Pandas\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u548c\u8bfb\u53d6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Pandas\u521b\u5efa\u4e00\u4e2aDataFrame\u5bf9\u8c61\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u64cd\u4f5c\u77e9\u9635\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">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><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u8bfb\u53d6\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = df.iloc[1, 2]  # \u8bfb\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>Pandas\u4e5f\u652f\u6301\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684DataFrame<\/p>\n<p>data = {&#39;A&#39;: [1.5, 2.3, 3.1], &#39;B&#39;: [4.2, 5.5, 6.8], &#39;C&#39;: [7.9, 8.6, 9.4]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u8bfb\u53d6\u6240\u6709\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>float_elements = df.select_dtypes(include=[&#39;float64&#39;])<\/p>\n<p>print(float_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5185\u7f6e\u5217\u8868\u8bfb\u53d6\u77e9\u9635<\/h3>\n<\/p>\n<p><p>\u5c3d\u7ba1NumPy\u548cPandas\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\uff0cPython\u7684\u5185\u7f6e\u5217\u8868\u4e5f\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u548c\u8bfb\u53d6\u77e9\u9635\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u521b\u5efa\u548c\u8bfb\u53d6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Python\u7684\u5185\u7f6e\u5217\u8868\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">matrix = [<\/p>\n<p>    [1, 2, 3],<\/p>\n<p>    [4, 5, 6],<\/p>\n<p>    [7, 8, 9]<\/p>\n<p>]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u8bfb\u53d6\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix[1][2]  # \u8bfb\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u5185\u7f6e\u5217\u8868\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u77e9\u9635<\/p>\n<p>matrix = [<\/p>\n<p>    [1.5, 2.3, 3.1],<\/p>\n<p>    [4.2, 5.5, 6.8],<\/p>\n<p>    [7.9, 8.6, 9.4]<\/p>\n<p>]<\/p>\n<h2><strong>\u8bfb\u53d6\u6240\u6709\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>float_elements = [element for row in matrix for element in row if isinstance(element, float)]<\/p>\n<p>print(float_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528SciPy\u8bfb\u53d6\u77e9\u9635<\/h3>\n<\/p>\n<p><p>SciPy\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684Python\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u6570\u5b66\u3001\u79d1\u5b66\u548c\u5de5\u7a0b\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5\u548c\u5bfc\u5165SciPy<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u5b89\u88c5SciPy\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165SciPy\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u521b\u5efa\u548c\u8bfb\u53d6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528SciPy\u521b\u5efa\u4e00\u4e2a\u77e9\u9635\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy import sparse<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a00\u758f\u77e9\u9635<\/strong><\/h2>\n<p>matrix = sparse.csr_matrix([[1, 0, 0], [0, 2, 0], [0, 0, 3]])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u8bfb\u53d6\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">element = matrix[1, 2]  # \u8bfb\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>print(element)  # \u8f93\u51fa\uff1a0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>SciPy\u4e5f\u652f\u6301\u8bfb\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u7a00\u758f\u77e9\u9635<\/p>\n<p>matrix = sparse.csr_matrix([[1.5, 0, 0], [0, 2.3, 0], [0, 0, 3.1]])<\/p>\n<h2><strong>\u8bfb\u53d6\u6240\u6709\u6d6e\u70b9\u6570<\/strong><\/h2>\n<p>float_elements = matrix.data[matrix.data.dtype == np.float64]<\/p>\n<p>print(float_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u5176\u4ed6Python\u5e93\u8bfb\u53d6\u77e9\u9635<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\uff0cPython\u8fd8\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u7528\u4e8e\u8bfb\u53d6\u548c\u64cd\u4f5c\u77e9\u9635\uff0c\u5982TensorFlow\u3001PyTorch\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528TensorFlow\u8bfb\u53d6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>TensorFlow\u662f\u4e00\u4e2a\u7528\u4e8e<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7684\u5f00\u6e90\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u77e9\u9635\u548c\u5f20\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tensorflow as tf<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>matrix = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=tf.int32)<\/p>\n<h2><strong>\u8bfb\u53d6\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u6570\u636e<\/strong><\/h2>\n<p>element = matrix[1, 2]  # \u8bfb\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>print(element.numpy())  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528PyTorch\u8bfb\u53d6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>PyTorch\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u7684\u5f00\u6e90\u5e93\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u77e9\u9635\u548c\u5f20\u91cf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import torch<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>matrix = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype=torch.int32)<\/p>\n<h2><strong>\u8bfb\u53d6\u77e9\u9635\u4e2d\u7684\u67d0\u4e2a\u6570\u636e<\/strong><\/h2>\n<p>element = matrix[1, 2]  # \u8bfb\u53d6\u7b2c\u4e8c\u884c\u7b2c\u4e09\u5217\u7684\u5143\u7d20<\/p>\n<p>print(element.item())  # \u8f93\u51fa\uff1a6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8bfb\u53d6\u77e9\u9635\u4e2d\u7279\u5b9a\u7684\u6570\u636e\u7c7b\u578b\u6709\u591a\u79cd\u65b9\u6cd5\uff0c<strong>\u4f7f\u7528NumPy\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528Pandas\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528\u5185\u7f6e\u5217\u8868\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528SciPy\u8bfb\u53d6\u77e9\u9635<\/strong>\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><p><strong>NumPy<\/strong>\u9002\u7528\u4e8e\u9700\u8981\u9ad8\u6548\u5904\u7406\u5927\u89c4\u6a21\u6570\u7ec4\u548c\u77e9\u9635\u7684\u6570\u636e\u5206\u6790\u4efb\u52a1\uff0c<strong>Pandas<\/strong>\u9002\u7528\u4e8e\u5904\u7406\u5177\u6709\u6807\u7b7e\u548c\u7d22\u5f15\u7684\u8868\u683c\u6570\u636e\uff0c<strong>\u5185\u7f6e\u5217\u8868<\/strong>\u9002\u7528\u4e8e\u7b80\u5355\u7684\u5c0f\u89c4\u6a21\u77e9\u9635\u64cd\u4f5c\uff0c<strong>SciPy<\/strong>\u9002\u7528\u4e8e\u9700\u8981\u5904\u7406\u7a00\u758f\u77e9\u9635\u548c\u9ad8\u7ea7\u79d1\u5b66\u8ba1\u7b97\u7684\u573a\u666f\uff0c<strong>TensorFlow\u548cPyTorch<\/strong>\u5219\u9002\u7528\u4e8e\u9700\u8981\u8fdb\u884c\u6df1\u5ea6\u5b66\u4e60\u548c\u673a\u5668\u5b66\u4e60\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u52a0\u9ad8\u6548\u5730\u8bfb\u53d6\u548c\u64cd\u4f5c\u77e9\u9635\u4e2d\u7279\u5b9a\u7684\u6570\u636e\u7c7b\u578b\uff0c\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6\u77e9\u9635\u7684\u7279\u5b9a\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u77e9\u9635\u3002\u8981\u8bfb\u53d6\u67d0\u4e2a\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u60a8\u53ef\u4ee5\u9996\u5148\u786e\u4fdd\u77e9\u9635\u7684\u5143\u7d20\u7c7b\u578b\u7b26\u5408\u60a8\u7684\u8981\u6c42\u3002\u4f7f\u7528<code>dtype<\/code>\u53c2\u6570\u521b\u5efa\u77e9\u9635\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u6570\u636e\u7c7b\u578b\u3002\u8bfb\u53d6\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6216\u6761\u4ef6\u7b5b\u9009\u6765\u83b7\u53d6\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u5143\u7d20\u3002<\/p>\n<p><strong>\u6709\u54ea\u4e9bPython\u5e93\u53ef\u4ee5\u5904\u7406\u77e9\u9635\u548c\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u9664\u4e86NumPy\uff0cPandas\u4e5f\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5e93\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u8868\u683c\u6570\u636e\u3002Pandas\u7684DataFrame\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u5e26\u6807\u7b7e\u7684\u77e9\u9635\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u9009\u62e9\u548c\u8fc7\u6ee4\u6570\u636e\u7c7b\u578b\u3002\u5728Pandas\u4e2d\uff0c\u4f7f\u7528<code>select_dtypes()<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5feb\u901f\u7b5b\u9009\u51fa\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u5217\u3002<\/p>\n<p><strong>\u5982\u4f55\u5224\u65ad\u77e9\u9635\u4e2d\u67d0\u4e2a\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528<code>type()<\/code>\u51fd\u6570\u6765\u68c0\u67e5\u77e9\u9635\u4e2d\u67d0\u4e2a\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\u3002\u5982\u679c\u662fNumPy\u6570\u7ec4\uff0c\u4f7f\u7528<code>dtype<\/code>\u5c5e\u6027\u4e5f\u53ef\u4ee5\u67e5\u770b\u6574\u4e2a\u6570\u7ec4\u7684\u6570\u636e\u7c7b\u578b\u3002\u8fd9\u6837\uff0c\u60a8\u80fd\u591f\u5feb\u901f\u4e86\u89e3\u77e9\u9635\u4e2d\u7684\u5143\u7d20\u662f\u6574\u6570\u3001\u6d6e\u70b9\u6570\u8fd8\u662f\u5176\u4ed6\u6570\u636e\u7c7b\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u8bfb\u53d6\u77e9\u9635\u4e2d\u7279\u5b9a\u6570\u636e\u7c7b\u578b\u7684\u51e0\u79cd\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528NumPy\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528Pandas\u8bfb\u53d6\u77e9\u9635\u3001\u4f7f\u7528\u5185\u7f6e\u5217 [&hellip;]","protected":false},"author":3,"featured_media":1128329,"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\/1128322"}],"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=1128322"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128322\/revisions"}],"predecessor-version":[{"id":1128331,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1128322\/revisions\/1128331"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1128329"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1128322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1128322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1128322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}