Excel表格一般情况下都有多个表单,每个表单读出来就是一个datafram对象
import os
import pandas as pd
filePath = 'E:\ProjectFile\File_Processing\XLSX\To_csv\data'
files = [i for i in os.listdir(filePath) if 'xlsx' in i ]
for file in files:
try:
print(file)
filenamePath = os.path.join(filePath, file)
dfs = pd.read_excel(filenamePath, None, index_col=0)
for types, df in dfs.items():
Newname = f'{file[:-5]}_{types}.csv'
NewfilenamePath = os.path.join(filePath, Newname)
df.to_csv(NewfilenamePath)
except:
pass
网友评论