Do any one know about this Error in python? how can I resolve this?

2024/10/5 19:21:02

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
Answer

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()

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

https://en.xdnf.cn/q/119185.html

Related Q&A

Pandas: Count Higher Ranks For Current Experiment Participants In Later Experiments (Part 1)

Learning Experiments In a series of learning experiments, I would like to count the number of participants in each experiment that improved their performance in subsequent experiments (Rank 1 is highes…

Pass variables into and out of exec [closed for not being clear. Modified and reuploaded] [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 3 years ago.Improve…

List Object Not Callable, Syntax Error for Text-Based RPG

Im having issues (still) with generating a random object, in this case a random herb found by foraging. Heres the code for the function:def collectPlants(self):if self.state == normal:print"%s spe…

Why does my Tkinter window background not change?

Ive a small program with a feature to change the background color of a different window than the frame I use to ask for the background color. (I hope you understand this.) The program is written in Pyt…

Combining a nested list without affecting the key and value direction in python

I have a program that stores data in a list. The current and desired output is in the format:# Current Input [{Devices: [laptops, tablets],ParentCategory: [computers, computers]},{Devices: [touch], Par…

Splitting very large csv files into smaller files

Is Dask proper to read large csv files in parallel and split them into multiple smaller files?

How to make this Python script to run subfolders too?

Which part of the codes do I need to change in order to include subfolders? File handle.py import glob import os import sys from typing import Listdef get_filenames(filepath: str, pattern: str) -> …

Why doesnt this recursive GCD function work? [duplicate]

This question already has answers here:Why does my recursive function return None?(4 answers)What is the purpose of the return statement? How is it different from printing?(15 answers)Closed 1 year …

How can I append \n at the end of the list in list comperhansion

I have this code:def table(h, w):table = [[. for i in range(w)] for j in range(h)]return tablewhich returns this[ [., ., .], [., ., .], [., ., .], [., ., .] ]How to make it return this?[[., ., .],[., …

Seaborn bar plot y axis has different values than expected

The y values in the Seaborn barplot are different than what my data shows.My data shows:yearmonth 2018-10 763308.0 2018-11 708366.0 2018-12 703952.0 2019-01 844039.0 2019-02 749583.…