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

yipeiwu_com5年前Python基础

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写入文件的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python xlsxwriter创建excel图表的方法

python xlsxwriter创建excel图表的方法

本文实例为大家分享了python xlsxwriter创建excel图表的具体代码,供大家参考,具体内容如 #coding=utf-8 import xlsxwriter fro...

python实现的简单抽奖系统实例

本文实例讲述了python实现的简单抽奖系统。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python #coding=utf-8 from Tkinte...

Python实现微信好友的数据分析

Python实现微信好友的数据分析

基于微信开放的个人号接口python库itchat,实现对微信好友的获取,并对省份、性别、微信签名做数据分析。 效果: 直接上代码,建三个空文本文件stopwords.txt,ne...

浅谈python日志的配置文件路径问题

如下所示: import logging import logging.config logging.config.fileConfig(path) logger = logging...

在Python中Dataframe通过print输出多行时显示省略号的实例

在Python中Dataframe通过print输出多行时显示省略号的实例

笔者使用Python进行数据分析时,通过print输出Dataframe中的数据,当Dataframe行数很多时,中间部分显示省略号,如下图所示: 0 项华祥 1...