{"id":1379,"date":"2020-10-04T10:00:57","date_gmt":"2020-10-04T10:00:57","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=1379"},"modified":"2021-02-09T10:01:40","modified_gmt":"2021-02-09T10:01:40","slug":"python%e4%bd%bf%e7%94%a8pandas%e5%90%88%e5%b9%b6excel%e8%a1%a8%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2020\/10\/python%e4%bd%bf%e7%94%a8pandas%e5%90%88%e5%b9%b6excel%e8%a1%a8%e6%a0%bc\/","title":{"rendered":"[Python]\u4f7f\u7528pandas\u5408\u5e76Excel\u8868\u683c"},"content":{"rendered":"

<\/p>\n

\u9700\u6c42\u5982\u4e0a\uff0cSheet1\u548cSheet2\u5206\u522b\u5b58\u653e\u4e86\u8bed\u6587\u6570\u5b66\u6210\u7ee9\uff0c\u9700\u8981\u5c06\u5176\u5408\u5e76\u653e\u5230Sheet3\u4e2d\uff0c\u8fd9\u4e2a\u96be\u70b9\u5728\u4e8e\uff0cSheet1\u548cSheet2\u4eba\u6570\u4e0d\u4e00\u6837\uff0c\u5e94\u8be5\u53d6 \u5e76\u96c6\u3002<\/p>\n

\n
import pandas as pd\n\ndf1 = pd.read_excel('\u5b66\u751f\u6210\u7ee9\u88682.xlsx', sheet_name='\u8bed\u6587')\ndf2 = pd.read_excel('\u5b66\u751f\u6210\u7ee9\u88682.xlsx', sheet_name='\u6570\u5b66')\n\nnewdf = df1.merge(df2, how='outer', on=['\u59d3\u540d', '\u6027\u522b']).fillna(0)\n\n\nwriter = pd.ExcelWriter('\u5b66\u751f\u6210\u7ee9\u88682.xlsx', mode='a')\nnewdf.to_excel(writer, sheet_name='\u6210\u7ee9\u603b\u8868', index=False)\nwriter.save()<\/code><\/pre>\n<\/div>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » [Python]\u4f7f\u7528pandas\u5408\u5e76Excel\u8868\u683c<\/a><\/p>","protected":false},"excerpt":{"rendered":"

\u9700\u6c42\u5982\u4e0a\uff0cSheet1\u548cSheet2\u5206\u522b\u5b58\u653e\u4e86\u8bed\u6587\u6570\u5b66\u6210\u7ee9\uff0c\u9700\u8981\u5c06\u5176\u5408\u5e76\u653e\u5230Sheet3\u4e2d\uff0c\u8fd9\u4e2a\u96be\u70b9\u5728\u4e8e\uff0cSheet1\u548cSheet2\u4eba\u6570\u4e0d\u4e00\u6837\uff0c\u5e94\u8be5\u53d6 \u5e76\u96c6\u3002 import pandas as pd df1 = pd.read_excel(‘\u5b66\u751f\u6210\u7ee9\u88682.xlsx’, sheet_name=’\u8bed\u6587’) df2 = pd.read_excel(‘\u5b66\u751f\u6210\u7ee9\u88682.xlsx’, sheet_name=’\u6570\u5b66’) newdf = df1.merge(df2, how=’outer’, on=[‘\u59d3\u540d’, ‘\u6027\u522b’]).fillna(0) writer = pd.ExcelWriter(‘\u5b66\u751f\u6210\u7ee9\u88682.xlsx’, mode=’a’) newdf.to_excel(writer, sheet_name=’\u6210\u7ee9\u603b\u8868’, index=False) writer.save() \u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def » [Python]\u4f7f\u7528pandas\u5408\u5e76Excel\u8868\u683c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[59],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1379"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1379"}],"version-history":[{"count":1,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1379\/revisions"}],"predecessor-version":[{"id":1380,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1379\/revisions\/1380"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}