1

I have a dict(image attached below): [1]: https://i.stack.imgur.com/n3SYv.png

The keys of the dict is a dataframe. When trying to upload this dict to json I had to convert column a to string type from interval type. But when I want to use the json I want to convert the values of column a back to interval type. Below are the things I've tried:

k = dict.keys()
for keys in k:
   dict[keys]["a"] = dict[keys]["a"].astype("interval")

But it throws the below error: TypeError: type <class 'str'> with value (-inf, -9999999.0] is not an interval

Can you please help me with the way to convert column a values from string to Interval types?

anaktha
  • 21
  • 2
  • I think this question has been answered already but without inf: https://stackoverflow.com/questions/65295837/turn-string-representation-of-interval-into-actual-interval-in-pandas inf can be converted with np.array([np.inf]).astype(int)[0] or math.inf (or -math.inf for negative infinity) – Ori Yarden PhD Jan 03 '23 at 16:11

1 Answers1

-1

(See Security of Python's eval() on untrusted strings?)

>>> class Foo(object):
...     pass
... 
>>> eval("Foo")
<class '__main__.Foo'>