获取Python错误:指定的列太多
我正在通过Conda和我的航站楼运行Python。给了我一个脚本,应该能够在没有错误的情况下运行。该脚本导入URL并将其读为CSV。这就是我得到的:
url = 'https://www.aoml.noaa.gov/hrd/hurdat/hurdat2.html'
data, storm, stormList = readHURDAT2(url)
columnnames= ['a,b,c,etc']
错误以下一行开头:
for line in pd.read_csv(url, header=None, names=columnnames, chunksize=1):
计算机在输出此错误消息之前运行多个迭代:
Too many columns specified: expected 20 and found 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之所以发生这种情况,是因为以HTML格式。我建议您将数据复制并粘贴到本地CSV文件中,并从中复制
read_csv
。另外,因为该文件具有特定格式分裂的格式文档标题行
和数据行
,均具有不同数量的列,您需要设置engine ='Python'
读取它。最后,最多有21列,而不是20列。代码应该看起来像这样:
This happens because the data in https://www.aoml.noaa.gov/hrd/hurdat/hurdat2.html is in HTML format. I'd recommend you copy and paste the data into a local CSV file and
read_csv
from it. Also, because the file has a specific format that splits the document intoHEADER LINES
andDATA LINES
, both with a different number of columns, you'd need to setengine='python'
to read it. Finally, there are the maximum of 21 columns, not 20.The code should look something like this: