Combine the contents of multiple tables into a new table (under the same folder, the table structure is the same)

In the same folder, select files with the same structure and combine them into a new table.

The names of files with the same structure contain the characters'MOD'

import pandas as pd
import os

p_path = r'D:\work\RS\test\20200813'
file_list = os.listdir(p_path)
PM = pd.DataFrame(data=[],columns=[],index=None)
for li in file_list[:]:
    if 'MOD' in li:
        data = pd.read_csv(r'{}/{}'.format(p_path,li))
        PM = pd.concat([PM,data],axis =0)
        print(li)
PM.to_csv(r'{}\{}'.format(p_path,'output.csv'),index=None)

 

Guess you like

Origin blog.csdn.net/ch206265/article/details/108881324