Python Forum
Removing nan values from a dict
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Removing nan values from a dict
#5
Assuming it is a numpy array.
import numpy as np

notadict = np.array([438.4, 439.18, 439.9, np.nan, np.nan])
print(notadict[(~np.isnan(notadict))], notadict)
print(np.delete(notadict, np.isnan(notadict)), notadict)
print(np.nan_to_num(notadict, nan=0.0), notadict)
print(np.nan_to_num(notadict, copy=False, nan=0.0), notadict)
Output:
[438.4 439.18 439.9 ] [438.4 439.18 439.9 nan nan] [438.4 439.18 439.9 ] [438.4 439.18 439.9 nan nan] [438.4 439.18 439.9 0. 0. ] [438.4 439.18 439.9 nan nan] [438.4 439.18 439.9 0. 0. ] [438.4 439.18 439.9 0. 0. ]
Notice that nan_to_num does the change in place if you use "copy=False".
tomtom likes this post
Reply


Messages In This Thread
Removing nan values from a dict - by tomtom - Oct-05-2021, 02:57 PM
RE: Removing nan values from a dict - by menator01 - Oct-05-2021, 03:33 PM
RE: Removing nan values from a dict - by tomtom - Oct-05-2021, 06:20 PM
RE: Removing nan values from a dict - by menator01 - Oct-05-2021, 06:38 PM
RE: Removing nan values from a dict - by bowlofred - Oct-05-2021, 03:39 PM
RE: Removing nan values from a dict - by tomtom - Oct-05-2021, 06:44 PM
RE: Removing nan values from a dict - by snippsat - Oct-05-2021, 04:17 PM
RE: Removing nan values from a dict - by deanhystad - Oct-05-2021, 06:16 PM
RE: Removing nan values from a dict - by tomtom - Oct-05-2021, 06:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  dict class override: how access parent values? Andrey 1 1,721 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  Trouble with converting list , dict to int values! faryad13 7 3,894 Sep-04-2020, 06:25 AM
Last Post: faryad13
  Sort a dict in dict cherry_cherry 4 90,567 Apr-08-2020, 12:25 PM
Last Post: perfringo
  How to access specific values from a dict? t4keheart 6 3,219 Feb-05-2020, 11:34 PM
Last Post: metulburr
  updating certain values in dict. with relation to their keys malevy 17 5,537 Nov-27-2019, 02:37 PM
Last Post: buran
  update dict as per range of values anna 7 3,183 Sep-13-2019, 04:37 PM
Last Post: anna
  match values against keys three dict anna 0 2,184 Feb-21-2019, 05:30 PM
Last Post: anna
  Compare Two Values in the Same Dict malonn 6 4,534 Aug-01-2018, 03:54 PM
Last Post: malonn
  sorting nested dict according to values merlem 6 17,793 Apr-01-2017, 10:01 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020