複数のexcelファイルをマージ

850 ワード

多くのexcelテーブルをまとめる必要があるので、次のスクリプトがあります.
import os
import glob
import pandas as pd

# drop duplications according to parameter 'on'
def merge_excel(path, id):
    all_data = pd.DataFrame()
    for f in glob.glob(path):
        print(f)
        df = pd.read_excel(f) #header=3             ,    0   
        df_not_null = df.dropna(subset=["       "])  # delete null on some columns
        all_data = all_data.append(df_not_null, ignore_index=True)
    return all_data.drop_duplicates(id,'last')

if __name__ == '__main__':
    source_path = "/Users/sunchenn/sunchenn/mergeExcel/exampleExcels/*.xlsx"
    target_path = "/Users/sunchenn/sunchenn/mergeExcel"

    df = merge_excel(source_path, "  ")
    df.to_excel(os.path.join(target_path,"Total.xlsx"),index=False)