简体   繁体   English

串联数据框python

[英]concatenating data frames python

I need to concatenate 6 data frames and csv file names are stored as 'all_files'. 我需要连接6个数据帧,并将csv文件名存储为“ 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 UnicodeDecodeError:“ utf-8”编解码器无法解码位置1的字节0xf6:无效的起始字节

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 = ',')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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