LoginSignup
0
0

自分用備忘録:複数tsvを1エクセルにまとめる

Posted at

自分用備忘録

def sum_excel():
    """
        フォルダごとに複数tsvを1つのexcelでまとめて出力
    """
    output_list = glob.glob(f"output1/*", recursive=True)
    for isp_path in output_list:
        isp = os.path.basename(os.path.dirname(isp_path))
        tsv_list = glob.glob(f"output1/{isp}/*.tsv", recursive=True)
        data = {}
        for tsv in tsv_list:
            df = pd.read_csv(tsv, dtype='string', sep='\t')
            data.setdefault(isp, df)
        # 1つのexcelに1シートごとに出力
        with pd.ExcelWriter(f'output1/total_{isp}.xlsx') as w:
            for df in data:
                print(df)
                data[df].to_excel(w, sheet_name=f"{df}")

"""

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0