在一个文件中,我有两个工作表,它们共享一些列。我需要根据列名合并工作表,如果列不存在,则添加它。即我有
第 1 页
+----+-------+--------------+
| id | name | description |
+----+-------+--------------+
| 1 | name1 | description1 |
| 2 | name2 | description2 |
+----+-------+--------------+
第 2 页
+----+-------+--------------+--------+
| id | name | description | title |
+----+-------+--------------+--------+
| 3 | name3 | description3 | title3 |
| 4 | name4 | description4 | title4 |
+----+-------+--------------+--------+
期望输出
+----+-------+--------------+--------+
| id | name | description | title |
+----+-------+--------------+--------+
| 1 | name1 | description1 | |
| 2 | name2 | description2 | |
| 3 | name3 | description3 | title3 |
| 4 | name4 | description4 | title4 |
+----+-------+--------------+--------+
有什么办法可以做到这一点?
答案1
你可以用python + pandas来做
import pandas as pd
import numpy as np
import glob
a = glob.glob("C:/Documents and Settings/Administrator/My Documents/*.xlsx")
all_data = pd.DataFrame()
for f in a:
df = pd.read_excel(f)
all_data = all_data.append(df,ignore_index=True,sort=False)
print all_data
这将合并你指定位置的所有数据,并显示