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=0
或1
为pd.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.