Adding file name in a Column while merging multible csv files to pandas- Python

后端 未结 1 1361
予麋鹿
予麋鹿 2021-02-06 19:38

I have multiple csv files in the same folder with all the same data columns,

20100104 080100;5369;5378.5;5365;5378;2368
20100104 080200;5378;5385;5377;5384.5;65         


        
1条回答
  •  野的像风
    2021-02-06 20:23

    Instead of using a list just use DataFrame's append.

    df = pd.DataFrame()
    for file_ in all_files:
        file_df = pd.read_csv(file_,sep=';', parse_dates=[0], infer_datetime_format=True,header=None )
        file_df['file_name'] = file_
        df = df.append(file_df)
    

    0 讨论(0)
提交回复
热议问题