SoFunction
Updated on 2025-03-02

Pandas method of writing multiple Sheets to files each time

Pandas writes multiple Sheets to a file, and can only be saved at one time, otherwise the file will be rewritten every time, and only the last write will be retained in the end.

# !usr/bin env python
# -*- coding: utf-8 -*- 
 
import pandas as pd
 
price_path = ''
df_price = pd.read_csv(price_path)
 
for i in xrange(4):
  sh = 'Sheet{}'.format(i+1)
  file_path = 'qimo_close_price.xlsx'
  raw_df = pd.read_excel(file_path, sheet_name=i)
 
  out_path = 'qimo_close_price_out.xlsx'
  raw = (raw_df, df_price, how='left')
  raw.to_excel(out_path, sheet_name=sh, index=False)

The above method of writing multiple sheets into files in the above article is all the content I share with you. I hope you can give you a reference and I hope you can support me more.