python拼接多个结构相同的excel表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_39928244/article/details/82561175

import pandas as pd
import os

Folder_Path = r'D:\5-Python\拼接\source'          
SaveFile_Path =  r'D:\5-Python\拼接\target'   
SaveFile_Name = r'汇总.csv'              
 

os.chdir(Folder_Path)
file_list = os.listdir()
 

print (len(file_list))
df = pd.read_csv(Folder_Path +'\\'+ file_list[0], engine='python', encoding='gbk')   #默认的c engine解析报错,指定python
df.to_csv(SaveFile_Path+'\\'+ SaveFile_Name, encoding='gbk', index=False)
 

for i in range(1,len(file_list), 1):
    df = pd.read_csv(Folder_Path + '\\'+ file_list[i], engine='python', encoding='gbk')
    df.to_csv(SaveFile_Path+'\\'+ SaveFile_Name, encoding='gbk', index=False, header=False, mode='a+')

print ('OK')

猜你喜欢

转载自blog.csdn.net/weixin_39928244/article/details/82561175
今日推荐