简体   繁体   中英

concatenating data frames python

I need to concatenate 6 data frames and csv file names are stored as 'all_files'. I have the following code:

df_from_each_file = (pd.read_csv(f, encoding = 'utf-8') for f in all_files)
data = pd.concat(df_from_each_file, ignore_index=True)

It gives the following error:

First line works well, but second line gives this error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf6 in position 1: invalid start byte

I tried different encodings but still gives the error. Do you guys have any idea?

@ user229519,使用encoding='latin-1'pd.read_csv并且还axis=01pd.concat

Maybe it's the separator, try either of these:

pd.read_csv(f,sep = ';')
pd.read_csv(f,sep = ',')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM