合并excel中多个sheet页

五十七 90 0

适用于相同字段的sheet合并

#!/usr/bin/env python3
# coding:utf-8
 
import pandas as pd
import argparse
import logging
 
parser = argparse.ArgumentParser(
    description="Combine excel sheets togather, let's go...")
parser.add_argument("-i", "--input", type=str, default="",
                    help="input excel document")
parser.add_argument("-d", "--debug", action='store_true', default=False,
                    help="debug mode")
args = parser.parse_args()
 
level = logging.DEBUG if args.debug else logging.INFO
logging.basicConfig(level=level,
                    format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s',
                    datefmt='%Y-%m-%d %H:%M:%S'
                    )
 
def main():
    sheets = pd.read_excel(args.input, sheet_name=None)
    dfs = pd.concat(sheets)
    logging.debug(dfs)
 
    dfs.to_excel('{}_total.xlsx'.format(args.input))
 
if __name__ == "__main__":
    main()

发表评论 取消回复
表情 图片 链接 代码

分享