pandas每次多Sheet写入文件 pandas每次多Sheet写入文件的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

pandas每次多Sheet写入文件 pandas每次多Sheet写入文件的方法

jiangjiane   2021-03-30 我要评论

pandas每次多Sheet写入文件,只能一次性存入,不然每次会重写文件,最后只保留最后一次的写入。

# !usr/bin env python
# -*- coding: utf-8 -*- 
 
import pandas as pd
 
price_path = 'ASHAREEODPRICE.csv'
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 = pd.merge(raw_df, df_price, how='left')
  raw.to_excel(out_path, sheet_name=sh, index=False)

以上这篇pandas每次多Sheet写入文件的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们