Python中怎么將一個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拆分為多個Excel問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。