简体   繁体   English

引发 KeyError(key) Python

[英]raise KeyError(key) Python

I get this error when executing my code do you have an idea how to fix it?执行代码时出现此错误您知道如何解决吗? here is the image and the code of the first lines of my csv file, the file is too big to display it entirely.这是我的 csv 文件的第一行的图像和代码,文件太大而无法完整显示。 the code is complete.代码是完整的。 i try to display the points on a map with geoplotlib我尝试使用 geoplotlib 在 map 上显示点

enter image description here在此处输入图像描述

import geoplotlib
import csv
import pandas as pd

data = pd.read_csv('E:\Projet de Memoir sur les tics/humdataAL.csv')
geoplotlib.dot(data)
geoplotlib.show()

It returns the following error:它返回以下错误:

Traceback (most recent call last):
  File "C:\Users\nsama\PycharmProjects\pythonProject\amara_project\venv\lib\site-packages\geoplotlib\__init__.py", line 32, in _runapp
    app.start()
  File "C:\Users\nsama\PycharmProjects\pythonProject\amara_project\venv\lib\site-packages\geoplotlib\core.py", line 364, in start
    self.proj.fit(BoundingBox.from_bboxes([l.bbox() for l in self.geoplotlib_config.layers]),
  File "C:\Users\nsama\PycharmProjects\pythonProject\amara_project\venv\lib\site-packages\geoplotlib\core.py", line 364, in <listcomp>
    self.proj.fit(BoundingBox.from_bboxes([l.bbox() for l in self.geoplotlib_config.layers]),
  File "C:\Users\nsama\PycharmProjects\pythonProject\amara_project\venv\lib\site-packages\geoplotlib\layers.py", line 159, in bbox
    return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])
  File "C:\Users\nsama\PycharmProjects\pythonProject\amara_project\venv\lib\site-packages\pandas\core\frame.py", line 3024, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\nsama\PycharmProjects\pythonProject\amara_project\venv\lib\site-packages\pandas\core\indexes\base.py", line 3082, in get_loc
    raise KeyError(key) from err
KeyError: 'lon'

Your CSV doesn't meet geoplotlib specifications.您的 CSV 不符合geoplotlib规范。 In particular, all rows must have columns named lat and lon in dataset.特别是,所有行都必须在数据集中具有名为latlon的列。

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

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