[英]Pandas read csv not separating columns
I am trying to read a csv encoded in utf-8 with a comma as separator but the dataframe is not separating any of the columns.我正在尝试使用逗号作为分隔符读取以 utf-8 编码的 csv,但数据框未分隔任何列。
This is an example of the csv file这是 csv 文件的示例
19,"Aero Biniza",\\N,"","BZS","BINIZA","Mexico","N" 19,"Aero Biniza",\\N,"","BZS","BINIZA","Mexico","N"
The whole file is available here整个文件在这里可用
https://raw.githubusercontent.com/jpatokal/openflights/master/data/airlines.dat https://raw.githubusercontent.com/jpatokal/openflights/master/data/airlines.dat
And this is my code这是我的代码
pd.read_csv(input_csv, encoding='utf-8') pd.read_csv(input_csv, encoding='utf-8')
I am probably doing something stupid but grateful if anyone can point it out.我可能正在做一些愚蠢的事情,但如果有人能指出它,我将不胜感激。
CSV need a header to have columns be named by them, looks like the csv in the link does not have that. CSV 需要一个标题才能由它们命名列,看起来链接中的 csv 没有那个。
In order to read a csv in that doesn't have a header you need to pass param header=None:为了读取没有标题的 csv,您需要传递参数 header=None:
df = pd.read_csv(file_path, header=None) df = pd.read_csv(file_path, header=None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.