Is there a way to remove nan from a dictionary filled with data?

后端 未结 4 1000
悲哀的现实
悲哀的现实 2021-01-12 06:51

I have a dictionary that is filled with data from two files I imported, but some of the data comes out as nan. How do I remove the pieces of data with nan?

My code i

4条回答
  •  清酒与你
    2021-01-12 07:44

    With simplejson

    import simplejson
    
    clean_dict  = simplejson.loads(simplejson.dumps(my_dict, ignore_nan=True))
    ## or depending on your needs
    clean_dict  = simplejson.loads(simplejson.dumps(my_dict, allow_nan=False))
    

提交回复
热议问题