
1つのファイルに2つのシートがあり、いくつかの列を共有しています。列名に基づいてシートを結合し、列が存在しない場合は追加する必要があります。つまり、
シート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
これにより、指定した場所のすべてのデータが結合され、表示されます。