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设计】。

相关文章

tensorflow中tf.slice和tf.gather切片函数的使用

tf.slice(input_, begin, size, name=None):按照指定的下标范围抽取连续区域的子集 tf.gather(params, indices, valida...

numpy中的meshgrid函数的使用

numpy官方文档meshgrid函数帮助文档https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.ht...

python将邻接矩阵输出成图的实现

python将邻接矩阵输出成图的实现

利用networkx,numpy,matplotlib,将邻接矩阵输出为图形。 1,自身确定一个邻接矩阵,然后通过循环的方式添加变,然后输出图像 import networkx as...

Python自动化测试工具Splinter简介和使用实例

Splinter 快速介绍官方网站:http://splinter.cobrateam.info/官方介绍:Splinter is an open source tool for tes...

Python批处理更改文件名os.rename的方法

在工作中,我们经常会遇到需要对大批量文件进行重命名的操作,而python提供了很简单的方法: import os #top是目标文件夹(绝对路径),os.walk会读取其内的文件及...