Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

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. the code is complete. i try to display the points on a map with geoplotlib

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
samaPycharmProjectspythonProjectamara_projectvenvlibsite-packagesgeoplotlib\__init__.py", line 32, in _runapp
    app.start()
  File "C:Users
samaPycharmProjectspythonProjectamara_projectvenvlibsite-packagesgeoplotlibcore.py", line 364, in start
    self.proj.fit(BoundingBox.from_bboxes([l.bbox() for l in self.geoplotlib_config.layers]),
  File "C:Users
samaPycharmProjectspythonProjectamara_projectvenvlibsite-packagesgeoplotlibcore.py", line 364, in <listcomp>
    self.proj.fit(BoundingBox.from_bboxes([l.bbox() for l in self.geoplotlib_config.layers]),
  File "C:Users
samaPycharmProjectspythonProjectamara_projectvenvlibsite-packagesgeoplotliblayers.py", line 159, in bbox
    return BoundingBox.from_points(lons=self.data['lon'], lats=self.data['lat'])
  File "C:Users
samaPycharmProjectspythonProjectamara_projectvenvlibsite-packagespandascoreframe.py", line 3024, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:Users
samaPycharmProjectspythonProjectamara_projectvenvlibsite-packagespandascoreindexesase.py", line 3082, in get_loc
    raise KeyError(key) from err
KeyError: 'lon'
question from:https://stackoverflow.com/questions/65863922/raise-keyerrorkey-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your CSV doesn't meet geoplotlib specifications. In particular, all rows must have columns named lat and lon in dataset.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...