{"id":2034,"date":"2021-11-18T09:21:17","date_gmt":"2021-11-18T01:21:17","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=2034"},"modified":"2021-11-18T09:21:17","modified_gmt":"2021-11-18T01:21:17","slug":"excel%e6%96%87%e4%bb%b6%e5%90%88%e5%b9%b6-python","status":"publish","type":"post","link":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/?p=2034","title":{"rendered":"excel\u6587\u4ef6\u5408\u5e76-Python"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>##import os\n##import pandas as pd\n##excels=&#91;pd.read_excel(fname)\n##        for fname in os.listdir(\".\/\")\n##        #if \".xlsx\" in fname\n##        if \".xls\" in fname\n##]\n##df =pd.concat(excels)\n##df.to_excel(\"\u7ed3\u679c\u6587\u4ef6.xlsx\",index=False)\n# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon Jan  7 12:07:56 2019\n\n@author: BIG DATA\n\"\"\"\n\nimport os\nimport pandas as pd\nimport numpy as np\n\ndir = \"H:\\\\Br.liutz\\\\\u53e3\u815421-7\\\\kq\"#\u8bbe\u7f6e\u5de5\u4f5c\u8def\u5f84\n\n#\u65b0\u5efa\u5217\u8868\uff0c\u5b58\u653e\u6587\u4ef6\u540d\uff08\u53ef\u4ee5\u5ffd\u7565\uff0c\u4f46\u662f\u4e3a\u4e86\u505a\u7684\u8fc7\u7a0b\u80fd\u5fc3\u91cc\u6709\u6570\uff0c\u5148\u653e\u4e0a\uff09\nfilename_excel = &#91;]\n\n#\u65b0\u5efa\u5217\u8868\uff0c\u5b58\u653e\u6bcf\u4e2a\u6587\u4ef6\u6570\u636e\u6846\uff08\u6bcf\u4e00\u4e2aexcel\u8bfb\u53d6\u540e\u5b58\u653e\u5728\u6570\u636e\u6846\uff09\nframes = &#91;]\n\nfor root, dirs, files in os.walk(dir):\n    for file in files:\n        #print(os.path.join(root,file))\n        filename_excel.append(os.path.join(root,file))\n        df = pd.read_excel(os.path.join(root,file)) #excel\u8f6c\u6362\u6210DataFrame\n        frames.append(df)\n#\u6253\u5370\u6587\u4ef6\u540d\nprint(filename_excel)   \n #\u5408\u5e76\u6240\u6709\u6570\u636e\nresult = pd.concat(frames)    \n\n#\u67e5\u770b\u5408\u5e76\u540e\u7684\u6570\u636e\nresult.head()\nresult.shape\n\nresult.to_csv('H:\\Br.liutz\\\u53e3\u815421-7\\kq\\\\kaoqin.csv',sep=',',index = False)#\u4fdd\u5b58\u5408\u5e76\u7684\u6570\u636e\u5230\u7535\u8111D\u76d8\u7684merge\u6587\u4ef6\u5939\u4e2d\uff0c\u5e76\u628a\u5408\u5e76\u540e\u7684\u6587\u4ef6\u547d\u540d\u4e3aa12.csv\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-2034","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2034"}],"version-history":[{"count":0,"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2034\/revisions"}],"wp:attachment":[{"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2034"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nr0jgk4d.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}