{"id":617,"date":"2017-12-15T15:45:37","date_gmt":"2017-12-15T07:45:37","guid":{"rendered":"http:\/\/cflin.com\/wordpress\/?p=617"},"modified":"2017-12-15T16:41:47","modified_gmt":"2017-12-15T08:41:47","slug":"pandassql-python-sample","status":"publish","type":"post","link":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample","title":{"rendered":"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6"},"content":{"rendered":"<h2>Pandas+SQL \u64cd\u4f5c &#8211; \u524d\u8a00<\/h2>\n<p><strong>Pandas+SQL<\/strong> \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u672c\u7bc7\u6587\u7ae0\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u00a0<a href=\"https:\/\/data.gov.tw\/dataset\/40448\">\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)<\/a> \u70ba\u8cc7\u6599\u4f86\u6e90\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 <a href=\"https:\/\/pandas.pydata.org\/\">pandas<\/a> \u642d\u914d SQL \u8a9e\u6cd5 \u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709 SQL \u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684 SQL \u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u3002<\/p>\n<h2>Pandas \u7c21\u4ecb<\/h2>\n<p><em>Pandas<\/em> \u662f <em>python<\/em> \u7684\u4e00\u500b\u6578\u64da\u5206\u6790\u6a21\u7d44\u5eab\uff0c\u65bc 2009 \u5e74\u5e95\u958b\u6e90\u51fa\u4f86\uff0c\u63d0\u4f9b\u9ad8\u6548\u80fd\u3001\u7c21\u6613\u4f7f\u7528\u7684\u8cc7\u6599\u683c\u5f0f (Data Frame) \u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u5feb\u901f\u64cd\u4f5c\u53ca\u5206\u6790\u8cc7\u6599\uff0c\u4e3b\u8981\u7279\u8272\u63cf\u8ff0\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u5728\u7570\u8cea\u6578\u64da\u7684\u8b80\u53d6\u3001\u8f49\u63db\u548c\u8655\u7406\u4e0a\uff0c\u8b93\u5206\u6790\u4eba\u54e1\u66f4\u5bb9\u6613\u8655\u7406\uff0c\u4f8b\u5982\uff1a\u5f9e\u5217\u6b04\u8a66\u7b97\u8868\u4e2d\u627e\u5230\u60f3\u8981\u7684\u503c\u3002<\/li>\n<li><em>Pandas<\/em> \u63d0\u4f9b\u5169\u7a2e\u4e3b\u8981\u7684\u8cc7\u6599\u7d50\u69cb\uff0c<em>Series<\/em> \u8207 <em>DataFrame<\/em>\u3002\n<ul>\n<li>Series\uff1a \u7528\u4f86\u8655\u7406\u6642\u9593\u5e8f\u5217\u76f8\u95dc\u7684\u8cc7\u6599(\u5982\u611f\u6e2c\u5668\u8cc7\u6599\u7b49)\uff0c\u4e3b\u8981\u70ba\u5efa\u7acb\u7d22\u5f15\u7684\u4e00\u7dad\u9663\u5217\u3002<\/li>\n<li>DataFrame\uff1a \u7528\u4f86\u8655\u7406\u7d50\u69cb\u5316(Table like)\u7684\u8cc7\u6599\uff0c\u6709\u5217\u7d22\u5f15\u8207\u6b04\u6a19\u7c64\u7684\u4e8c\u7dad\u8cc7\u6599\u96c6\uff0c\u4f8b\u5982\uff1a\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u3001 CSV\u00a0 \u7b49\u7b49\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u900f\u904e\u8f09\u5165\u81f3 Pandas \u7684\u8cc7\u6599\u7d50\u69cb\u7269\u4ef6\u5f8c\uff0c\u900f\u904e\u7d50\u69cb\u5316\u7269\u4ef6\u6240\u63d0\u4f9b\u7684\u65b9\u6cd5\uff0c\u5feb\u901f\u5730\u8cc7\u6599\u524d\u8655\u7406\u3002\u4f8b\u5982\uff1a\u8cc7\u6599\u88dc\u503c\uff0c\u7a7a\u503c\u53bb\u9664\u6216\u53d6\u4ee3\u7b49\u3002<\/li>\n<li>\u66f4\u591a\u7684\u8f38\u5165\u4f86\u6e90\u53ca\u8f38\u51fa\u6574\u5408\u6027\uff0c\u4f8b\u5982\uff1a\u53ef\u4ee5\u5f9e\u8cc7\u6599\u5eab\u8b80\u53d6\u8cc7\u6599\u9032\u5165 Dataframe \uff0c\u4e5f\u53ef\u5c07\u8655\u7406\u5b8c\u7684\u8cc7\u6599\u5b58\u56de\u8cc7\u6599\u5eab\u3002<\/li>\n<\/ul>\n<p>\u672c\u7bc7\u6587\u7ae0\u5c31\u662f\u4f7f\u7528 DataFrame \u642d\u914d\u95dc\u9023\u5f0f\u8cc7\u6599\u5eab\uff0c\u4f7f\u7528 SQL \u8a9e\u6cd5\u9032\u884c\u8cc7\u6599\u67e5\u8a62\u7be9\u9078\uff0c\u800c\u672a\u4f86\u6709\u6642\u9593\u518d\u6574\u7406\u66f4\u591a\u5176\u4ed6 Pandas \u76f8\u95dc\u7684\u61c9\u7528\u7bc4\u4f8b\u3002<\/p>\n<h2 id=\"pandas\">\u5b89\u88dd Pandas<\/h2>\n<p>Python \u5b89\u88dd\u65b9\u5f0f\u4e00\u6a23\u90fd\u662f\u900f\u904e pip install \u5373\u53ef\u5b8c\u6210\u5b89\u88dd\uff0c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>pip install pandas  \r\n<\/code><\/pre>\n<p>\u5176\u4ed6\u4ecb\u7d39\u53ef\u4ee5\u53c3\u8003\u00a0<a href=\"http:\/\/pandas.pydata.org\/\">\u5b98\u65b9\u7db2\u7ad9<\/a><\/p>\n<h2>JSON<\/h2>\n<p><b>JSON<\/b>\uff08<b>J<\/b>ava<b>S<\/b>cript\u00a0<b>O<\/b>bject\u00a0<b>N<\/b>otation\uff09\u662f\u4e00\u7a2e\u7531<a title=\"\u9053\u683c\u62c9\u65af\u00b7\u514b\u7f85\u514b\u798f\u7279\" href=\"https:\/\/zh.wikipedia.org\/wiki\/%E9%81%93%E6%A0%BC%E6%8B%89%E6%96%AF%C2%B7%E5%85%8B%E7%BE%85%E5%85%8B%E7%A6%8F%E7%89%B9\">\u9053\u683c\u62c9\u65af\u00b7\u514b\u7f85\u514b\u798f\u7279<\/a>\u69cb\u60f3\u8a2d\u8a08\u3001\u8f15\u91cf\u7d1a\u7684<a class=\"new\" title=\"\u8cc7\u6599\u4ea4\u63db\u8a9e\u8a00\uff08\u9801\u9762\u4e0d\u5b58\u5728\uff09\" href=\"https:\/\/zh.wikipedia.org\/w\/index.php?title=%E8%B3%87%E6%96%99%E4%BA%A4%E6%8F%9B%E8%AA%9E%E8%A8%80&amp;action=edit&amp;redlink=1\">\u8cc7\u6599\u4ea4\u63db\u8a9e\u8a00<\/a>\uff0c\u4ee5\u6587\u5b57\u70ba\u57fa\u790e\uff0c\u4e14\u6613\u65bc\u8b93\u4eba\u95b1\u8b80\u3002\u5118\u7ba1 JSON \u662f <a class=\"mw-redirect\" title=\"Javascript\" href=\"https:\/\/zh.wikipedia.org\/wiki\/Javascript\">Javascript\u00a0<\/a>\u7684\u4e00\u500b\u5b50\u96c6\uff0c\u4f46 JSON \u662f\u7368\u7acb\u65bc\u8a9e\u8a00\u7684<a title=\"\u6587\u5b57\u6a94\u6848\" href=\"https:\/\/zh.wikipedia.org\/wiki\/%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6\">\u6587\u5b57\u683c\u5f0f<\/a>\uff0c\u4e26\u4e14\u63a1\u7528\u4e86\u985e\u4f3c\u65bc <a class=\"mw-redirect\" title=\"C\u8a9e\u8a00\" href=\"https:\/\/zh.wikipedia.org\/wiki\/C%E8%AA%9E%E8%A8%80\">C\u8a9e\u8a00<\/a> \u5bb6\u65cf\u7684\u4e00\u4e9b\u7fd2\u6163\u3002\u6b64\u7a2e\u683c\u5f0f\u8207XML\u683c\u5f0f\u5e38\u88ab\u7528\u65bcAPI\u7684\u8cc7\u6599\u56de\u50b3\u683c\u5f0f\u3002\u672c\u7bc7\u6587\u7ae0\u7684\u7a0b\u5f0f\u78bc\u7bc4\u4f8b\u5c31\u662f\u4ee5 JSON \u683c\u5f0f\u7684\u5167\u5bb9\u70ba\u8cc7\u6599\u7684\u8f38\u5165\u4f86\u6e90\u3002<\/p>\n<h2>\u7bc4\u4f8b\u7a0b\u5f0f\u78bc<\/h2>\n<p>\u6b64\u7bc4\u4f8b\u7a0b\u5f0f\u4e3b\u8981\u6d41\u7a0b\u5927\u81f4\u70ba\uff1a<\/p>\n<ol>\n<li>\u900f\u904e\u00a0<em>requests\u00a0<\/em>\u547c\u53eb\u653f\u5e9c\u516c\u958b\u8cc7\u6599\u7684 <em>API<\/em> \u5f97\u5230\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19\u7684\u8cc7\u6599( JSON \u683c\u5f0f)<\/li>\n<li>\u900f\u904e\u00a0<em>json.loads\u00a0<\/em>\u51fd\u6578\u5c07\u8cc7\u6599\u8b80\u5165<\/li>\n<li>\u4f7f\u7528\u00a0<em>pandas\u00a0DataFrame<\/em> \u7522\u751f\u51fa\u8cc7\u6599\u6846<\/li>\n<li>\u900f\u904e\u00a0<em>sqlalchemy\u00a0<\/em>\u6a21\u7d44\u4e2d\u7684 create_engine \u51fd\u6578\u4f86\u5efa\u7acb sqlite \u7684\u9023\u7dda \uff0c\u4e26\u8a2d\u5b9a\u5c07\u8cc7\u6599\u8868\u5132\u5b58\u5728 memory \u4e2d(\u63d0\u4f9b\u4e00\u6b21\u6027\u7684\u64cd\u4f5c\u4f7f\u7528\uff0c\u82e5\u9700\u8981\u6c38\u4e45\u5132\u5b58\u5247\u53ef\u4ee5\u5beb\u5165\u6a94\u6848\u4e2d)<\/li>\n<li>\u4f7f\u7528 SQL \u8a9e\u6cd5\u4f5c\u53d6\u51fa\u7279\u5b9a\u7684\u6b04\u4f4d(\u7e23\u5e02\u3001\u5340\u57df\u3001\u5e73\u5747 PM2.5 \u503c)\u4e26\u4ee5 PM2.5 \u7684\u503c\u7531\u5927\u81f3\u5c0f\u6392\u5e8f\u3002<\/li>\n<\/ol>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport json\r\nimport requests\r\nimport pandas as pd\r\n'''\r\n\u8cc7\u6599\u5eab\u7684\u8b80\u5beb\u51fd\u6578\u53ef\u4ee5\u4f7f\u7528 SQLAlchemy\uff0c\u652f\u63f4 PostgreSQL, MySQL, Oracle,\r\nMicrosoft SQL server \u7b49\u8cc7\u6599\u5eab...\r\n'''\r\nfrom sqlalchemy import create_engine\r\n\r\nreq = requests.get('http:\/\/opendata2.epa.gov.tw\/AQI.json')\r\ndata = json.loads(req.content.decode('utf8'))\r\ndf = pd.DataFrame(data)\r\n\r\n#\u900f\u904esqlalchemy\u6a21\u7d44\u4e2d\u7684create_engine\u51fd\u6578\u4f86\u5efa\u7acbsqlite\u7684\u9023\u7dda\r\n#\u4e26\u8a2d\u5b9a\u5c07\u8cc7\u6599\u8868\u5132\u5b58\u5728memory\u4e2d(\u63d0\u4f9b\u4e00\u6b21\u6027\u7684\u64cd\u4f5c\u4f7f\u7528\uff0c\u82e5\u9700\u8981\u6c38\u4e45\u5132\u5b58\u5247\u53ef\u4ee5\u5beb\u5165\u6a94\u6848\u4e2d)\r\nengine = create_engine('sqlite:\/\/\/:memory:')\r\ndf.to_sql('db_table', engine, index=False)\r\nprint(pd.read_sql_query('SELECT `County` as `\u7e23\u5e02`, `SiteName` as `\u5340\u57df`, \\\r\n\tCAST(`PM2.5_AVG` AS int) as `PM2.5` FROM `db_table` \\\r\n\torder by CAST(`PM2.5_AVG` AS int) ASC', engine))\r\n<\/pre>\n<p><a href=\"https:\/\/notebooks.azure.com\/chifu\/libraries\/train\/html\/aqi.ipynb\">\u9ede\u6211\u89c0\u770b\u57f7\u884c\u7bc4\u4f8b\u00a0<\/a>(\u4f7f\u7528 Microsoft Azure Notebooks )<\/p>\n<figure id=\"attachment_618\" aria-describedby=\"caption-attachment-618\" style=\"width: 1981px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg\"><img loading=\"lazy\" class=\"wp-image-618 size-full\" src=\"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg\" alt=\"Pandas+SQL \u57f7\u884c\u6548\u679c\u622a\u5716\" width=\"1981\" height=\"3046\" srcset=\"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg 1981w, https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924-195x300.jpeg 195w, https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924-768x1181.jpeg 768w, https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924-666x1024.jpeg 666w\" sizes=\"(max-width: 1981px) 100vw, 1981px\" \/><\/a><figcaption id=\"caption-attachment-618\" class=\"wp-caption-text\">Pandas+SQL \u57f7\u884c\u6548\u679c\u622a\u5716<\/figcaption><\/figure>\n<p>\u82e5\u6709\u5176\u4ed6\u60f3\u6cd5\uff0c\u4f8b\u5982\uff1a\u60f3\u77e5\u9053\u54ea\u500b\u7e23\u5e02\u7684\u6574\u9ad4\u5e73\u5747\u7a7a\u6c23\u54c1\u8cea\u8f03\u5dee\u5c31\u53ef\u4ee5\u5728 SQL \u8a9e\u6cd5\u4e2d\u4f7f\u7528 GROUP BY \u8a9e\u6cd5\uff0c\u5c0d\u65bc SQL \u8a9e\u6cd5\u719f\u6089\u7684\u8a71\u5c31\u80fd\u8f15\u6613\u5730\u85c9\u7531\u6539\u8b8a\u67e5\u8a62\u7684\u8a9e\u6cd5\u4f86\u7372\u5f97\u60f3\u67e5\u8a62 \/ \u7be9\u9078\u7684\u8cc7\u6599\u3002<\/p>\n<p>PS. \u5c0d\u65bcPython\u8a9e\u6cd5\u4e0a\u6709\u7591\u554f\u53ef\u4ee5\u53c3\u8003<a href=\"http:\/\/cflin.com\/wordpress\/python-%e7%a8%8b%e5%bc%8f%e8%a8%ad%e8%a8%88%e6%8a%95%e5%bd%b1%e7%89%87\">\u8ab2\u7a0b\u6295\u5f71\u7247<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pandas+SQL \u64cd\u4f5c &#8211; \u524d\u8a00 Pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u672c\u7bc7\u6587\u7ae0\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u00a0\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI) \u70ba\u8cc7\u6599\u4f86\u6e90\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 pandas \u642d\u914d SQL \u8a9e\u6cd5 \u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709 SQL \u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684 SQL \u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u3002 Pandas \u7c21\u4ecb Pandas \u662f python \u7684\u4e00\u500b\u6578\u64da\u5206\u6790\u6a21\u7d44\u5eab\uff0c\u65bc 2009 \u5e74\u5e95\u958b\u6e90\u51fa\u4f86\uff0c\u63d0\u4f9b\u9ad8\u6548\u80fd\u3001\u7c21\u6613\u4f7f\u7528\u7684\u8cc7\u6599\u683c\u5f0f (Data Frame) \u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u5feb\u901f\u64cd\u4f5c\u53ca\u5206\u6790\u8cc7\u6599\uff0c\u4e3b\u8981\u7279\u8272\u63cf\u8ff0\u5982\u4e0b\uff1a \u5728\u7570\u8cea\u6578\u64da\u7684\u8b80\u53d6\u3001\u8f49\u63db\u548c\u8655\u7406\u4e0a\uff0c\u8b93\u5206\u6790\u4eba\u54e1\u66f4\u5bb9\u6613\u8655\u7406\uff0c\u4f8b\u5982\uff1a\u5f9e\u5217\u6b04\u8a66\u7b97\u8868\u4e2d\u627e\u5230\u60f3\u8981\u7684\u503c\u3002 Pandas \u63d0\u4f9b\u5169\u7a2e\u4e3b\u8981\u7684\u8cc7\u6599\u7d50\u69cb\uff0cSeries \u8207 DataFrame\u3002 Series\uff1a \u7528\u4f86\u8655\u7406\u6642\u9593\u5e8f\u5217\u76f8\u95dc\u7684\u8cc7\u6599(\u5982\u611f\u6e2c\u5668\u8cc7\u6599\u7b49)\uff0c\u4e3b\u8981\u70ba\u5efa\u7acb\u7d22\u5f15\u7684\u4e00\u7dad\u9663\u5217\u3002 DataFrame\uff1a \u7528\u4f86\u8655\u7406\u7d50\u69cb\u5316(Table like)\u7684\u8cc7\u6599\uff0c\u6709\u5217\u7d22\u5f15\u8207\u6b04\u6a19\u7c64\u7684\u4e8c\u7dad\u8cc7\u6599\u96c6\uff0c\u4f8b\u5982\uff1a\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u3001 CSV\u00a0 \u7b49\u7b49\u3002 \u900f\u904e\u8f09\u5165\u81f3 Pandas \u7684\u8cc7\u6599\u7d50\u69cb\u7269\u4ef6\u5f8c\uff0c\u900f\u904e\u7d50\u69cb\u5316\u7269\u4ef6\u6240\u63d0\u4f9b\u7684\u65b9\u6cd5\uff0c\u5feb\u901f\u5730\u8cc7\u6599\u524d\u8655\u7406\u3002\u4f8b\u5982\uff1a\u8cc7\u6599\u88dc\u503c\uff0c\u7a7a\u503c\u53bb\u9664\u6216\u53d6\u4ee3\u7b49\u3002 \u66f4\u591a\u7684\u8f38\u5165\u4f86\u6e90\u53ca\u8f38\u51fa\u6574\u5408\u6027\uff0c\u4f8b\u5982\uff1a\u53ef\u4ee5\u5f9e\u8cc7\u6599\u5eab\u8b80\u53d6\u8cc7\u6599\u9032\u5165 Dataframe \uff0c\u4e5f\u53ef\u5c07\u8655\u7406\u5b8c\u7684\u8cc7\u6599\u5b58\u56de\u8cc7\u6599\u5eab\u3002 \u672c\u7bc7\u6587\u7ae0\u5c31\u662f\u4f7f\u7528 DataFrame \u642d\u914d\u95dc\u9023\u5f0f\u8cc7\u6599\u5eab\uff0c\u4f7f\u7528 SQL \u8a9e\u6cd5\u9032\u884c\u8cc7\u6599\u67e5\u8a62\u7be9\u9078\uff0c\u800c\u672a\u4f86\u6709\u6642\u9593\u518d\u6574\u7406\u66f4\u591a\u5176\u4ed6 Pandas \u76f8\u95dc\u7684\u61c9\u7528\u7bc4\u4f8b\u3002 \u5b89\u88dd Pandas Python &hellip; <a href=\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[2],"tags":[21,19,11,20,23,22],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6 - \u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)<\/title>\n<meta name=\"description\" content=\"pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)\u70ba\u8cc7\u6599\u4f86\u6e90\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528pandas\u642d\u914dSQL\u8a9e\u6cd5\u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709SQL\u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684SQL\u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u770b\u770b\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample\" \/>\n<meta property=\"og:locale\" content=\"zh_TW\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6 - \u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)\" \/>\n<meta property=\"og:description\" content=\"pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)\u70ba\u8cc7\u6599\u4f86\u6e90\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528pandas\u642d\u914dSQL\u8a9e\u6cd5\u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709SQL\u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684SQL\u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u770b\u770b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample\" \/>\n<meta property=\"og:site_name\" content=\"\u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-15T07:45:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-15T08:41:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Chifu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cflin.com\/wordpress\/#website\",\"url\":\"https:\/\/cflin.com\/wordpress\/\",\"name\":\"\u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)\",\"description\":\"\u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed python \u8ab2\u7a0b\u76f8\u95dc\u8cc7\u6599\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cflin.com\/wordpress\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-TW\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#primaryimage\",\"url\":\"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg\",\"contentUrl\":\"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#webpage\",\"url\":\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample\",\"name\":\"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6 - \u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)\",\"isPartOf\":{\"@id\":\"https:\/\/cflin.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#primaryimage\"},\"datePublished\":\"2017-12-15T07:45:37+00:00\",\"dateModified\":\"2017-12-15T08:41:47+00:00\",\"author\":{\"@id\":\"https:\/\/cflin.com\/wordpress\/#\/schema\/person\/fcc9937e50465bfaa039229ad12d89aa\"},\"description\":\"pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)\u70ba\u8cc7\u6599\u4f86\u6e90\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528pandas\u642d\u914dSQL\u8a9e\u6cd5\u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709SQL\u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684SQL\u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u770b\u770b\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#breadcrumb\"},\"inLanguage\":\"zh-TW\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9801\",\"item\":\"https:\/\/cflin.com\/wordpress\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/cflin.com\/wordpress\/#\/schema\/person\/fcc9937e50465bfaa039229ad12d89aa\",\"name\":\"Chifu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-TW\",\"@id\":\"https:\/\/cflin.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/83c3d40c89fb05d334f2a3eddcfb4ac7?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/83c3d40c89fb05d334f2a3eddcfb4ac7?s=96&d=mm&r=g\",\"caption\":\"Chifu\"},\"sameAs\":[\"http:\/\/cflin.com\"],\"url\":\"https:\/\/cflin.com\/wordpress\/author\/daky\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6 - \u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)","description":"pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)\u70ba\u8cc7\u6599\u4f86\u6e90\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528pandas\u642d\u914dSQL\u8a9e\u6cd5\u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709SQL\u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684SQL\u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u770b\u770b\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample","og_locale":"zh_TW","og_type":"article","og_title":"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6 - \u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)","og_description":"pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)\u70ba\u8cc7\u6599\u4f86\u6e90\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528pandas\u642d\u914dSQL\u8a9e\u6cd5\u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709SQL\u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684SQL\u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u770b\u770b\u3002","og_url":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample","og_site_name":"\u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)","article_published_time":"2017-12-15T07:45:37+00:00","article_modified_time":"2017-12-15T08:41:47+00:00","og_image":[{"url":"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Written by":"Chifu","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/cflin.com\/wordpress\/#website","url":"https:\/\/cflin.com\/wordpress\/","name":"\u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)","description":"\u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed python \u8ab2\u7a0b\u76f8\u95dc\u8cc7\u6599","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cflin.com\/wordpress\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-TW"},{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#primaryimage","url":"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg","contentUrl":"https:\/\/cflin.com\/wordpress\/wp-content\/uploads\/2017\/12\/FireShot-Capture-042-train_aqi.ipynb-chifu-Microsoft-A_-https___notebooks.azure_.com_chifu_-e1513324113924.jpeg"},{"@type":"WebPage","@id":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#webpage","url":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample","name":"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6 - \u53f0\u5927\u7cfb\u7d71\u8a13\u7df4\u73ed\u8ab2\u7a0b\u7db2\u9801 (\u6797\u5947\u8ce6)","isPartOf":{"@id":"https:\/\/cflin.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#primaryimage"},"datePublished":"2017-12-15T07:45:37+00:00","dateModified":"2017-12-15T08:41:47+00:00","author":{"@id":"https:\/\/cflin.com\/wordpress\/#\/schema\/person\/fcc9937e50465bfaa039229ad12d89aa"},"description":"pandas+SQL \u7684\u64cd\u4f5c\u7bc4\u4f8b\uff0c\u4ee5\u653f\u5e9c\u958b\u653e\u8cc7\u6599\u5e73\u53f0\u4e2d\u7684\u7a7a\u6c23\u54c1\u8cea\u6307\u6a19(AQI)\u70ba\u8cc7\u6599\u4f86\u6e90\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528pandas\u642d\u914dSQL\u8a9e\u6cd5\u4f86\u505a\u8cc7\u6599\u641c\u5c0b\uff0c\u5c0d\u65bc\u5df2\u7d93\u6709SQL\u8a9e\u6cd5\u64cd\u4f5c\u57fa\u790e\u7684\u4eba\uff0c\u53ef\u4ee5\u7528\u4e4b\u524d\u5b78\u904e\u7684SQL\u8a9e\u6cd5\u5feb\u901f\u7684\u641c\u5c0b\u4e26\u7be9\u9078\u51fa\u6240\u9700\u8981\u7684\u8cc7\u6599\uff0c\u63d0\u4f9b\u5927\u5bb6\u53c3\u8003\u770b\u770b\u3002","breadcrumb":{"@id":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#breadcrumb"},"inLanguage":"zh-TW","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cflin.com\/wordpress\/617\/pandassql-python-sample#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9801","item":"https:\/\/cflin.com\/wordpress"},{"@type":"ListItem","position":2,"name":"Pandas+SQL-\u7a7a\u6c23\u54c1\u8cea\u8cc7\u6599\u64f7\u53d6"}]},{"@type":"Person","@id":"https:\/\/cflin.com\/wordpress\/#\/schema\/person\/fcc9937e50465bfaa039229ad12d89aa","name":"Chifu","image":{"@type":"ImageObject","inLanguage":"zh-TW","@id":"https:\/\/cflin.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/83c3d40c89fb05d334f2a3eddcfb4ac7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/83c3d40c89fb05d334f2a3eddcfb4ac7?s=96&d=mm&r=g","caption":"Chifu"},"sameAs":["http:\/\/cflin.com"],"url":"https:\/\/cflin.com\/wordpress\/author\/daky"}]}},"_links":{"self":[{"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/posts\/617"}],"collection":[{"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/comments?post=617"}],"version-history":[{"count":7,"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/posts\/617\/revisions"}],"predecessor-version":[{"id":627,"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/posts\/617\/revisions\/627"}],"wp:attachment":[{"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/media?parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/categories?post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cflin.com\/wordpress\/wp-json\/wp\/v2\/tags?post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}