Python-Pandas Library implementation EXCEL Data is split into different tables , And batch naming , By the way, review the display of the text progress bar

<>Python-Pandas Library implementation EXCEL Data is split into different tables

Why : Persisting in laziness is the first productive force , Colleagues said that there are about 100000 lines of data , You need to split into different tables based on the values in a column , At the same time, the file name should be changed to the corresponding region + residential quarters + code + name , Easy email .

<>Pandas library +os Library implementation

use os Library to create a folder ,Pandas Achieve split , By the way, review the display of the text progress bar :

* os library ,os.path.exists(path) Judge whether there is a corresponding path ;os.mkdir(path) establish
* Pandas library : After de duplicating the columns to be split , Select the corresponding number of rows , Through the index to achieve the need to select the region , residential quarters , code , Name , last to_excel Method implementation
* Text progress bar : adopt count Real time statistics have been generated EXCEL number , Through and len( Split column after de duplication ) Compare and realize split progress display .
<> Code section
#-*- coding = utf-8 -*- #@Time:2020/4/24 19:02 #@Author:OULA-WANG
#@File:SplitExcel.PY import pandas as pd import os data = pd.read_excel(
'./data.xlsx')# Read data data_list = list(data[' name '].drop_duplicates())# De reprocessing longth =
len(data_list)# Calculate the total quantity path = './SplitExcel' if not os.path.exists(path):
# Does this folder exist in the current folder os.mkdir(path)# Create this folder count = 0 for item in data_list:
data_select= data[data[' name ']==item]# elect item Corresponding line Bigzone = data_select.iat[0,0]
# Values that need to participate in file naming Smallzone = data_select.iat[0,1] service_code = data_select.iat[0,2]
data_select.to_excel('./SplitExcel/{0:}-{1:}-{2:}-{3:}.xlsx'.format(Bigzone,
Smallzone,service_code,item),index=False)# Generated according to the corresponding value EXCEL file count += 1 print(
'\rEXCEL There are two types in the table {} Names , Splitting page {} Home data , Split progress :{:.2%}'.format(longth, count, count /
longth),end="") print('\n{} All names have been split , Please go SplitExcel Folder to view the split file data .'.format(
longth))

# Life is short , I use it Python#, I've been studying for just two months , I don't feel like I'm getting started .Python It really works , keep trying , Strive to be an amateur programmer ..

Technology