有人知道python中的此错误吗?我该如何解决? [英] Do any one know about this Error in python? how can I resolve this?
问题描述
我正在使用MapBoxGl Python库在地图上绘制数据,这是我的代码,它从Pandas DataFrame获取纬度,经度和点,并尝试制作geojson,这是代码
I am plotting the data with MapBoxGl Python Library on maps, here is my code which is taking the latitude, longitude and points from the Pandas DataFrame and trying to make the geojson, here is the code
data4 = df_to_geojson(result, properties= ['speed'], lat='lat', lon='lon')
print (data4)
但是我遇到此错误,我不熟悉该错误,我一直在寻找它,但是没有找到任何解决方案:
but I am getting this error, I am not familiar with the error, I looked for it but didn't find any solution:
> --------------------------------------------------------------------------- ValueError Traceback (most recent call
> last) ~\Anaconda3\lib\site-packages\IPython\core\formatters.py in
> __call__(self, obj)
> 691 type_pprinters=self.type_printers,
> 692 deferred_pprinters=self.deferred_printers)
> --> 693 printer.pretty(obj)
> 694 printer.flush()
> 695 return stream.getvalue()
>
> ~\Anaconda3\lib\site-packages\IPython\lib\pretty.py in pretty(self,
> obj)
> 363 if cls in self.type_pprinters:
> 364 # printer registered in self.type_pprinters
> --> 365 return self.type_pprinters[cls](obj, self, cycle)
> 366 else:
> 367 # deferred printer
>
> ~\Anaconda3\lib\site-packages\IPython\lib\pretty.py in inner(obj, p,
> cycle)
> 594 if basetype is not None and typ is not basetype and typ.__repr__ != basetype.__repr__:
> 595 # If the subclass provides its own repr, use it instead.
> --> 596 return p.text(typ.__repr__(obj))
> 597
> 598 if cycle:
>
> ~\Anaconda3\lib\site-packages\geojson\base.py in __repr__(self)
> 25
> 26 def __repr__(self):
> ---> 27 return geojson.dumps(self, sort_keys=True)
> 28
> 29 __str__ = __repr__
>
> ~\Anaconda3\lib\site-packages\geojson\codec.py in dumps(obj, cls,
> allow_nan, **kwargs)
> 30 def dumps(obj, cls=GeoJSONEncoder, allow_nan=False, **kwargs):
> 31 return json.dumps(to_mapping(obj),
> ---> 32 cls=cls, allow_nan=allow_nan, **kwargs)
> 33
> 34
>
> ~\Anaconda3\lib\json\__init__.py in dumps(obj, skipkeys, ensure_ascii,
> check_circular, allow_nan, cls, indent, separators, default,
> sort_keys, **kw)
> 236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
> 237 separators=separators, default=default, sort_keys=sort_keys,
> --> 238 **kw).encode(obj)
> 239
> 240
>
> ~\Anaconda3\lib\json\encoder.py in encode(self, o)
> 197 # exceptions aren't as detailed. The list call should be roughly
> 198 # equivalent to the PySequence_Fast that ''.join() would do.
> --> 199 chunks = self.iterencode(o, _one_shot=True)
> 200 if not isinstance(chunks, (list, tuple)):
> 201 chunks = list(chunks)
>
> ~\Anaconda3\lib\json\encoder.py in iterencode(self, o, _one_shot)
> 255 self.key_separator, self.item_separator, self.sort_keys,
> 256 self.skipkeys, _one_shot)
> --> 257 return _iterencode(o, 0)
> 258
> 259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
>
> ValueError: Out of range float values are not JSON compliant
推荐答案
好,我得到了我的问题的正确答案,当然我删除了所有NAN值,但数据框中仍然有inf
值,例如我试图找到整个专栏的描述的人,例如
well, I got the correct answer for my question of course I removed all NAN values but still there were inf
values in my dataframe, so as Instructed by someone I tried to find the description of the whole column such as
df['column'].describe()
此行给出了最小值,最大值,均值std和其他值,所以我的最大值将是inf,因此我使用以下命令删除了该inf值,并且可以正常工作
this line gave the min, max, mean std and other values, so my max value was going to inf, so I removed this inf value with the following command and it worked
df = df[~df.isin([np.nan, np.inf, -np.inf]).any(1)]
这解决了我的问题. 解决方案
this solved my issue. Reference for the solution
这篇关于有人知道python中的此错误吗?我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!