{"id":470,"date":"2024-05-03T21:13:46","date_gmt":"2024-05-03T13:13:46","guid":{"rendered":"https:\/\/chenyl.fun\/?p=470"},"modified":"2024-05-05T21:53:55","modified_gmt":"2024-05-05T13:53:55","slug":"python-tips","status":"publish","type":"post","link":"https:\/\/chenyl.fun\/?p=470","title":{"rendered":"Python Tips"},"content":{"rendered":"\n<p>python\u4e2d\u591a\u884c\u5b57\u7b26\u4e32\u7684\u5c55\u793a\uff1a\u7528&#8221;&#8217; &#8221;&#8217;\u6216\u8005 &#8220;&#8221;&#8221; &#8220;&#8221;&#8221; \u6765\u8868\u793a\uff0c\u5373\u53ef\u5c55\u793a\u591a\u884c\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>Pandas\u521d\u8bd5<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd\nfrom sqlalchemy import create_engine\n\nengine = create_engine('mysql+pymysql:\/\/wpadmin:wpadmin@localhost:3306\/test')\nsql = \"\"\"SELECT\n        *\n    FROM\n        student\n    WHERE\n        id = '12345';\"\"\"\nquery = pd.read_sql_query(sql, engine)\nprint(query)\n\ndf_write = pd.DataFrame({'id': ['12', '13'], 'code': ['someshit', 'shitagain']})\n# if_exists='append'\u610f\u601d\u662f\u5982\u679cstudent\u8868\u5b58\u5728\uff0c\u5219\u5411\u8868\u4e2d\u8ffd\u52a0\u6570\u636e\ndf_write.to_sql('student', engine, index=False, if_exists='append')\n<\/pre>\n\n\n\n<p><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/72347359\">Python\u8fde\u63a5mysql\u6570\u636e\u5e93\u6781\u7b80\u6559\u7a0b\uff08pandas\uff09<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>python\u4e2d\u591a\u884c\u5b57\u7b26\u4e32\u7684\u5c55\u793a\uff1a\u7528&#8221;&#8217; &#8221;&#8217;\u6216\u8005 &#038;#8220 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[8],"_links":{"self":[{"href":"https:\/\/chenyl.fun\/index.php?rest_route=\/wp\/v2\/posts\/470"}],"collection":[{"href":"https:\/\/chenyl.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chenyl.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chenyl.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chenyl.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=470"}],"version-history":[{"count":3,"href":"https:\/\/chenyl.fun\/index.php?rest_route=\/wp\/v2\/posts\/470\/revisions"}],"predecessor-version":[{"id":477,"href":"https:\/\/chenyl.fun\/index.php?rest_route=\/wp\/v2\/posts\/470\/revisions\/477"}],"wp:attachment":[{"href":"https:\/\/chenyl.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chenyl.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chenyl.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}