pythonはpansdasを使って一括処理xlsxを使ってcsvに回転します.

7815 ワード

pandsを使って一括処理します.xlsxからcsvに変えます.
import pandas as pd
import os
import re


def xlsx_to_csv_pd(istr,ik):
    df1=pd.read_excel(istr)
    df1.to_csv(r'F:\  '+'\\'+ik+'.csv',index=False)

def get_one_type_file_list(InputFilePath, FileSuffix):
   
    TempPath = InputFilePath
    while ((TempPath[0] == '/') or (TempPath[0] == '\\')):
        InputFilePath = TempPath[1:]
        TempPath = InputFilePath
    while ((TempPath[-1] == '/') or (TempPath[-1] == '\\')):
        InputFilePath = TempPath[:-2]
        TempPath = InputFilePath

    FileList = []
    PathList = []
    
    FileNames = os.listdir(InputFilePath)

    FindStr = r".*?\." + FileSuffix + "$"  #         .+     
    if (len(FileNames) > 0):
        for fn in FileNames:
            result = re.match(FindStr, fn)
            if result != None:
                strTemp = InputFilePath + "\\" + fn
               
                PathList.append((InputFilePath + "\\" + fn))
               
                FileList.append(fn)
           
    return (PathList, FileList)


if __name__ == '__main__':
    strInputDir = r'F:\BIAOZHUN'
    strFileSuffix='xlsx'
    lstFilePath, lstFileName = get_one_type_file_list(strInputDir, strFileSuffix)

    for ik,istr in enumerate (lstFilePath):
        xlsx_to_csv_pd(istr,lstFileName[ik])

    print ('  ')