python 拆分excel工作表_Python将一个Excel拆分为多个Excel
本文實例為大家分享了Python將一個Excel拆分為多個Excel的具體代碼,供大家參考,具體內容如下
原始文檔如下圖所示
將銷售部門一、二、三科分別存為三個Excel
代碼如下
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 9 20:25:31 2018
@author: Lenovo
"""
import pandas as pd
data = pd.read_excel("E:\data1.xls")
rows = data.shape[0] #獲取行數 shape[1]獲取列數
department_list = []
for i in range(rows):
temp = data["銷售部門"][i]
if temp not in department_list:
department_list.append(temp) #將銷售部門的分類存在一個列表中
for department in department_list:
new_df = pd.DataFrame()
for i in range (0, rows):
if data["銷售部門"][i] == department:
new_df = pd.concat([new_df, data.iloc[[i],:]], axis = 0, ignore_index = True)
new_df.to_excel(str(department)+".xls", sheet_name=department, index = False) #將每個銷售部門存成一個新excel
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
總結
以上是生活随笔為你收集整理的python 拆分excel工作表_Python将一个Excel拆分为多个Excel的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: go build 无文件_Go 质量保证
- 下一篇: 菜鸟教程python正则表达式_Pyth