{"id":1120448,"date":"2025-01-08T18:56:35","date_gmt":"2025-01-08T10:56:35","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1120448.html"},"modified":"2025-01-08T18:56:37","modified_gmt":"2025-01-08T10:56:37","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e8%a1%a8%e4%b8%ad%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1120448.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u83b7\u53d6\u8868\u4e2d\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\/25083115\/80ad9b8b-61f9-4618-a2eb-561bde346717.webp\" alt=\"python\u4e2d\u5982\u4f55\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\u7684\u51e0\u79cd\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528pandas\u5e93\u3001\u4f7f\u7528sqlalchemy\u5e93\u3001\u4f7f\u7528sqlite3\u5e93\u3001\u76f4\u63a5\u67e5\u8be2\u6570\u636e\u5e93\u7cfb\u7edf\u8868\u3002<\/strong> <\/p>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<strong>\u4f7f\u7528pandas\u5e93<\/strong> \u662f\u4e00\u79cd\u975e\u5e38\u65b9\u4fbf\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u8bfb\u53d6\u8868\u4e2d\u7684\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u63d0\u4f9b\u5173\u4e8e\u6570\u636e\u7c7b\u578b\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u901a\u8fc7<code>pandas.read_sql<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5c06SQL\u67e5\u8be2\u7ed3\u679c\u76f4\u63a5\u8bfb\u5165\u5230DataFrame\u4e2d\uff0c\u7136\u540e\u4f7f\u7528DataFrame\u7684<code>dtypes<\/code>\u5c5e\u6027\u6765\u67e5\u770b\u5404\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u8be6\u7ec6\u4e86\u89e3\u8fd9\u4e00\u70b9\uff0c\u4e0b\u9762\u6211\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pandas\u5e93\u6765\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\uff0c\u5e76\u6df1\u5165\u63a2\u8ba8\u8be5\u65b9\u6cd5\u7684\u5b9e\u9645\u5e94\u7528\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528pandas\u5e93<\/h3>\n<\/p>\n<p><p><strong>Pandas<\/strong>\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u5b83\u80fd\u975e\u5e38\u65b9\u4fbf\u5730\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528pandas\u6765\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230SQLite\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;example.db&#39;)<\/p>\n<h2><strong>\u4f7f\u7528pandas\u8bfb\u53d6SQL\u8868<\/strong><\/h2>\n<p>df = pd.read_sql_query(&quot;SELECT * FROM your_table&quot;, conn)<\/p>\n<h2><strong>\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>print(df.dtypes)<\/p>\n<h2><strong>\u5173\u95ed\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/h2>\n<p>conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1\u3001\u8fde\u63a5\u6570\u636e\u5e93<\/h4>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002\u8fd9\u91cc\u4ee5SQLite\u6570\u636e\u5e93\u4e3a\u4f8b\uff0c\u4f46pandas\u5e93\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u8fde\u63a5\u65b9\u5f0f\uff0c\u5305\u62ecMySQL\u3001PostgreSQL\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230SQLite\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;example.db&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u8bfb\u53d6\u8868\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>pandas.read_sql_query<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06SQL\u67e5\u8be2\u7ed3\u679c\u52a0\u8f7d\u5230\u4e00\u4e2aDataFrame\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">df = pd.read_sql_query(&quot;SELECT * FROM your_table&quot;, conn)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528DataFrame\u7684<code>dtypes<\/code>\u5c5e\u6027\u53ef\u4ee5\u83b7\u53d6\u6bcf\u4e00\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(df.dtypes)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528sqlalchemy\u5e93<\/h3>\n<\/p>\n<p><p><strong>SQLAlchemy<\/strong>\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684SQL\u5de5\u5177\u5305\u548c\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u5668\uff08ORM\uff09\uff0c\u53ef\u4ee5\u7528\u4e8ePython\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u9ad8\u7ea7\u7684\u3001\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u6765\u64cd\u4f5c\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8fde\u63a5\u6570\u636e\u5e93<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u5f15\u64ce\u5e76\u8fde\u63a5\u5230\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce<\/strong><\/h2>\n<p>engine = create_engine(&#39;sqlite:\/\/\/example.db&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u53cd\u5c04\u8868\u7ed3\u6784<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528SQLAlchemy\u7684\u53cd\u5c04\u529f\u80fd\uff0c\u53ef\u4ee5\u4ece\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u8868\u7684\u5143\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import MetaData, Table<\/p>\n<h2><strong>\u521b\u5efaMetaData\u5bf9\u8c61<\/strong><\/h2>\n<p>metadata = MetaData()<\/p>\n<h2><strong>\u53cd\u5c04\u8868\u7ed3\u6784<\/strong><\/h2>\n<p>your_table = Table(&#39;your_table&#39;, metadata, autoload_with=engine)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u901a\u8fc7\u8bbf\u95ee\u8868\u5bf9\u8c61\u7684\u5217\u5c5e\u6027\uff0c\u53ef\u4ee5\u83b7\u53d6\u6bcf\u4e00\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for column in your_table.c:<\/p>\n<p>    print(f&quot;Column: {column.name}, Type: {column.type}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528sqlite3\u5e93<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662fSQLite\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528sqlite3\u5e93\u6765\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u8fde\u63a5\u6570\u636e\u5e93<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230SQLite\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;example.db&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u83b7\u53d6\u8868\u4fe1\u606f<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528sqlite3\u5e93\u7684<code>PRAGMA table_info<\/code>\u547d\u4ee4\uff0c\u53ef\u4ee5\u83b7\u53d6\u8868\u7684\u5143\u6570\u636e\uff0c\u5305\u62ec\u6bcf\u4e00\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">cursor = conn.execute(&quot;PRAGMA table_info(your_table)&quot;)<\/p>\n<p>for row in cursor:<\/p>\n<p>    print(f&quot;Column: {row[1]}, Type: {row[2]}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u76f4\u63a5\u67e5\u8be2\u6570\u636e\u5e93\u7cfb\u7edf\u8868<\/h3>\n<\/p>\n<p><p>\u5927\u591a\u6570\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7cfb\u7edf\u90fd\u7ef4\u62a4\u7740\u7cfb\u7edf\u8868\uff0c\u5b58\u50a8\u5173\u4e8e\u6570\u636e\u5e93\u5bf9\u8c61\u7684\u5143\u6570\u636e\u3002\u53ef\u4ee5\u76f4\u63a5\u67e5\u8be2\u8fd9\u4e9b\u7cfb\u7edf\u8868\u6765\u83b7\u53d6\u8868\u4e2d\u5217\u7684\u4fe1\u606f\u53ca\u5176\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001MySQL\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u5728MySQL\u4e2d\uff0c\u53ef\u4ee5\u67e5\u8be2<code>information_schema.columns<\/code>\u8868\u6765\u83b7\u53d6\u5217\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-sql\">SELECT COLUMN_NAME, DATA_TYPE<\/p>\n<p>FROM information_schema.columns<\/p>\n<p>WHERE table_name = &#39;your_table&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001PostgreSQL\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u5728PostgreSQL\u4e2d\uff0c\u53ef\u4ee5\u67e5\u8be2<code>information_schema.columns<\/code>\u8868\u6765\u83b7\u53d6\u5217\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-sql\">SELECT column_name, data_type<\/p>\n<p>FROM information_schema.columns<\/p>\n<p>WHERE table_name = &#39;your_table&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u7efc\u5408\u5e94\u7528\u5b9e\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u66f4\u597d\u5730\u5c55\u793a\u4e0a\u8ff0\u65b9\u6cd5\u7684\u5b9e\u9645\u5e94\u7528\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u7efc\u5408\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u5982\u4f55\u7ed3\u5408pandas\u548csqlalchemy\u5e93\u6765\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sqlalchemy import create_engine, MetaData, Table<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce<\/strong><\/h2>\n<p>engine = create_engine(&#39;sqlite:\/\/\/example.db&#39;)<\/p>\n<h2><strong>\u4f7f\u7528pandas\u8bfb\u53d6SQL\u8868<\/strong><\/h2>\n<p>df = pd.read_sql_query(&quot;SELECT * FROM your_table&quot;, engine)<\/p>\n<h2><strong>\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>print(&quot;Pandas DataFrame data types:&quot;)<\/p>\n<p>print(df.dtypes)<\/p>\n<h2><strong>\u521b\u5efaMetaData\u5bf9\u8c61<\/strong><\/h2>\n<p>metadata = MetaData()<\/p>\n<h2><strong>\u53cd\u5c04\u8868\u7ed3\u6784<\/strong><\/h2>\n<p>your_table = Table(&#39;your_table&#39;, metadata, autoload_with=engine)<\/p>\n<h2><strong>\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>print(&quot;\\nSQLAlchemy Table data types:&quot;)<\/p>\n<p>for column in your_table.c:<\/p>\n<p>    print(f&quot;Column: {column.name}, Type: {column.type}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6ce8\u610f\u4e8b\u9879\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6570\u636e\u5e93\u8fde\u63a5\u7ba1\u7406<\/strong>\uff1a\u5728\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u65f6\uff0c\u6ce8\u610f\u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\uff0c\u907f\u514d\u8fde\u63a5\u6cc4\u6f0f\u3002\u53ef\u4ee5\u4f7f\u7528\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u6216\u663e\u5f0f\u5173\u95ed\u8fde\u63a5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6027\u80fd\u8003\u8651<\/strong>\uff1a\u5728\u5904\u7406\u5927\u8868\u65f6\uff0c\u4f7f\u7528pandas\u8bfb\u53d6\u6574\u4e2a\u8868\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u95ee\u9898\u3002\u53ef\u4ee5\u8003\u8651\u5206\u6279\u6b21\u8bfb\u53d6\u6216\u53ea\u8bfb\u53d6\u5fc5\u8981\u7684\u5217\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/strong>\uff1a\u4e0d\u540c\u6570\u636e\u5e93\u7684\u6570\u636e\u7c7b\u578b\u53ef\u80fd\u6709\u6240\u4e0d\u540c\uff0c\u6ce8\u610f\u5728Python\u4e2d\u5904\u7406\u76f8\u5e94\u7684\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u6027<\/strong>\uff1a\u5728\u6267\u884cSQL\u67e5\u8be2\u65f6\uff0c\u907f\u514dSQL\u6ce8\u5165\u653b\u51fb\uff0c\u4f18\u5148\u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728Python\u4e2d\u83b7\u53d6\u8868\u4e2d\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4e0d\u4ec5\u9002\u7528\u4e8eSQLite\u6570\u636e\u5e93\uff0c\u4e5f\u9002\u7528\u4e8e\u5176\u4ed6\u4e3b\u6d41\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u5982MySQL\u3001PostgreSQL\u7b49\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u770bPandas DataFrame\u7684\u5217\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5728\u4f7f\u7528Pandas\u5e93\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>DataFrame.dtypes<\/code>\u5c5e\u6027\u6765\u67e5\u770b\u6bcf\u4e00\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002\u8be5\u5c5e\u6027\u4f1a\u8fd4\u56de\u4e00\u4e2aSeries\uff0c\u5176\u4e2d\u7d22\u5f15\u662f\u5217\u540d\uff0c\u503c\u662f\u5bf9\u5e94\u7684\u5217\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u83b7\u53d6\u6570\u636e\u7c7b\u578b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndf = pd.read_csv(&#39;your_file.csv&#39;)\nprint(df.dtypes)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u5feb\u901f\u4e86\u89e3\u6570\u636e\u4e2d\u5404\u5217\u7684\u7c7b\u578b\uff0c\u4fbf\u4e8e\u540e\u7eed\u7684\u6570\u636e\u5904\u7406\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528SQLAlchemy\u65f6\uff0c\u5982\u4f55\u83b7\u53d6\u6570\u636e\u5e93\u8868\u7684\u5217\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u4f7f\u7528SQLAlchemy\u8fde\u63a5\u6570\u636e\u5e93\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>inspect<\/code>\u6a21\u5757\u6765\u83b7\u53d6\u8868\u7684\u5217\u4fe1\u606f\uff0c\u5305\u62ec\u6570\u636e\u7c7b\u578b\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">from sqlalchemy import create_engine, inspect\n\nengine = create_engine(&#39;your_database_url&#39;)\ninspector = inspect(engine)\n\ncolumns = inspector.get_columns(&#39;your_table_name&#39;)\nfor column in columns:\n    print(column[&#39;name&#39;], column[&#39;type&#39;])\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u904d\u5386\u6307\u5b9a\u8868\u7684\u6240\u6709\u5217\u5e76\u6253\u5370\u51fa\u5217\u540d\u53ca\u5176\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u83b7\u53d6NumPy\u6570\u7ec4\u7684\u5143\u7d20\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5bf9\u4e8eNumPy\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528<code>dtype<\/code>\u5c5e\u6027\u6765\u83b7\u53d6\u6570\u7ec4\u7684\u5143\u7d20\u6570\u636e\u7c7b\u578b\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\n\narr = np.array([1, 2, 3])\nprint(arr.dtype)\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u60a8\u53ef\u4ee5\u4e86\u89e3NumPy\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5e2e\u52a9\u60a8\u5728\u8fdb\u884c\u6570\u503c\u8ba1\u7b97\u65f6\u505a\u51fa\u5408\u9002\u7684\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u83b7\u53d6\u8868\u4e2d\u6570\u636e\u7c7b\u578b\u7684\u51e0\u79cd\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528pandas\u5e93\u3001\u4f7f\u7528sqlalchemy\u5e93\u3001\u4f7f\u7528sqlit [&hellip;]","protected":false},"author":3,"featured_media":1120450,"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\/1120448"}],"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=1120448"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120448\/revisions"}],"predecessor-version":[{"id":1120451,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1120448\/revisions\/1120451"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1120450"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1120448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1120448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1120448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}