The code is as follows
import os import pandas as pd df =
pd.DataFrame(columns=[' Serial number ',' Event name ',' Name of our account ',' Account name of the other party ',' flow time ',' operator ',' a turnover ',' Water mark ',' Sector code '])
l = [] num = [] def search(path): parents = os.listdir(path) sum = 0 for parent
in parents: # Returns the names of all files and folders in the specified path , And stored in a list child = os.path.join(path,parent) if
os.path.isdir(child): # Multiple paths will be combined search(child) elif os.path.isfile(child): #
If it's a catalog , Then continue to traverse the files in the subdirectory if os.path.splitext(child)[1] == '.xls': #
Split file name and file extension , And the extension is 'xls' d = pd.read_excel(child) for i in range(len(d)):
num.append(os.path.split(child)[1][0:9]) l.append(d)
#search(r'C:\\Users\aming\\Desktop\\ Behavior analysis of College Students \\ Logistics data \\ Student data _LHJ_YJ')
search(r'C:\\Users\aming\\Desktop\\ Behavior analysis of College Students \\ Logistics data \\ Student data _LHJ_YJ\1250111\2012-8-1_2014-7-15')
df = pd.concat(l) da = pd.Series(num) df[' Student number '] = da df =
df.drop(columns=[' Serial number ',' Sector code ',' Serial number ',' operator ',' Water mark '],axis=1) # Delete entire column as NAN Column of
df.to_excel('rone.xlsx',index=False) # Save as result file
Technology