欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python將一個Excel拆分為多個Excel

 更新時間:2018年11月07日 11:18:42   作者:qq_41816368  
這篇文章主要為大家詳細介紹了Python將一個Excel拆分為多個Excel,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Python將一個Excel拆分為多個Excel的具體代碼,供大家參考,具體內(nèi)容如下

原始文檔如下圖所示

將銷售部門一、二、三科分別存為三個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] #獲取行數(shù) shape[1]獲取列數(shù)
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

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論