使用python获取多个excel第一列,汇总并去重数据到一个excel中
时间: 2023-03-22 21:03:06 浏览: 107
获取沪深300日行情数据并存入Excel文件_300_excel获取_python_数据开发_wind_
5星 · 资源好评率100%
\u6211\u80fd\u7406\u89e3\u60a8\u7684\u95ee\u9898\u3002\u5f53\u60a8\u4f7f\u7528Python\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528pandas\u5e93\u6765\u8bfb\u53d6Excel\u6587\u4ef6\uff0c\u5e76\u5c06\u6570\u636e\u540c\u65f6\u6c47\u603b\u5230\u4e00\u4e2aExcel\u6587\u4ef6\u4e2d\u7684\u7b2c\u4e00\u5217\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0bPython\u4ee3\u7801\u5b8c\u6210\uff1a
```python
import pandas as pd
# 读取多个Excel文件的第一列数据并汇总
path_list = ["file1.xlsx", "file2.xlsx", "file3.xlsx"]
df_list = []
for path in path_list:
df = pd.read_excel(path)
df_list.append(df.iloc[:, 0])
result = pd.concat(df_list)
# 将汇总的数据写入Excel文件的第一列
writer = pd.ExcelWriter("result.xlsx")
result.to_excel(writer, index=False, header=False, sheet_name="Sheet1")
writer.save()
```
\u4e0a\u9762\u7684Python\u4ee3\u7801\u4f7f\u7528pandas\u5e93\u8bfb\u53d6\u4e86\u591a\u4e2aExcel\u6587\u4ef6\uff0c\u6c47\u603b\u540e\u8fd4\u56de\u4e00\u4e2a\u6570\u636e\u5bf9\u8c61\u3002\u6700\u540e\uff0c\u5c06\u6c47\u603b\u7684\u6570\u636e\u5199\u5165\u5230\u4e00\u4e2aExcel\u6587\u4ef6\u4e2d\u7684\u7b2c\u4e00\u5217\uff0c\u4e14\u4e0d\u4f1a\u4fdd\u7559\u8868\u5934\u3002\u4e0b\u9762\u7684Python\u4ee3\u7801\u53ef\u4ee5\u5c06\u6570\u636e\u5199\u5165Excel\u6587\u4ef6\u4e2d\u7684\u7b2c\u4e00\u5217\uff0c\u4f46\u4f1a\u4fdd\u7559\u8868\u5934\uff1a
```python
import pandas as pd
# 读取多个Excel文件的第一列数据并汇总
path_list = ["file1.xlsx", "file2.xlsx", "file3.xlsx"]
df_list = []
for path in path_list:
df = pd.read_excel(path)
df_list.append(df.iloc[:, 0])
result = pd.concat(df_list)
# 将汇总的数据写入Excel文件的第一列
writer = pd.ExcelWriter("result.xlsx")
result.to_excel
阅读全文