Does anyone know about this error in python? how can i solve this?

I draw data using MapBoxGl Python Library on maps, here is my code that takes latitude, longitude and points from Pandas DataFrame and tries to make geojson, here is the code

data4 = df_to_geojson(result, properties= ['speed'], lat='lat', lon='lon') print (data4) 

but I get this error, I am not familiar with the error, I searched for it, but did not 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 
0
source share
2 answers

Well, I got the right answer to my question, of course, I deleted all the NAN values, but there were still inf values โ€‹โ€‹in my data framework, since I instructed someone, I tried to find a description of the entire column, such as

 df['column'].describe() 

this line gave the values โ€‹โ€‹min, max, mean std and other values, so my maximum value was going to inf, so I deleted this value inf with the following command and worked

 df = df[~df.isin([np.nan, np.inf, -np.inf]).any(1)] 

this solved my problem. Solution Link

0
source

Are there any NaNs in your framework? If so, this issue seems to be related. Itโ€™s hard for me to say exactly what is wrong, not seeing the contents of the data part in question, but a possible correction is to remove any NaN or other unerizable values โ€‹โ€‹before calling df_to_geojson ().

0
source

All Articles