1

I have a pandas dataframe converted into a dictionary (OrderedDict) and now I need to look for real NaN values (not the 'nan' string values) without pandas/numpy methods (as it should be independent from these packages). The dictionary looks like this:

OrderedDict([('concentration', ['5', '5', '5', '5', '5', nan, 'nan', 'nan', 'nan', 'nan', 'nan']),
 ('val', [6.0, 6.0, 6.0, 7.0, 8.0, 9.0, nan, nan, 0.0, 3.0, nan])])

I would like to have something like this:

keys = odict.keys()
count = len(odict[keys[0]])
for current in range(count):
        row = []
        for item in table:
            column = table[item]
            value = column[current]
            if >>>value is not nan<<<:
                row.append("MISSING")
            elif value is not None:
                row.append("value")
            else:
                row.append("something else")
        print(row)

Can anybody help?

EDIT: The full solution for me is not so easy to find within the answers/comments from the duplicate question. That's why I add it here as a quote:

... Better to use a try/except construction: def is_nan(x): try: return math.isnan(x) except: return False – Rob

Mike McKerns
  • 33,715
  • 8
  • 119
  • 139
Antje Janosch
  • 1,154
  • 5
  • 19
  • 37

0 Answers0