Question: I have the following dictionary:

```
my_dict = {'fields': ['id': 1.0,
  'name': 'aaa',
  'type': 'string'},
 {'id': 3.0,
  'name': 'eee',
  'type': 'string'},

 {'id': nan,
  'name': 'bbb',
  'type': 'string'},

 {'id': 4.0,
  'name': 'ccc',
  'type': 'string'},

 {'id': nan,
  'name': 'ddd',
  'type': 'string'}],

'type': 'struct'
}

```

From this dictionary, I would like to drop the dictionary with the `id` value `nan` value and would like to get the following.

```
my_updated_dict = {'fields': ['id': 1.0,
  'name': 'aaa',
  'type': 'string'},

 {'id': 3.0,
  'name': 'eee',
  'type': 'string'},

 {'id': 4.0,
  'name': 'ccc',
  'type': 'string'}],

'type': 'struct'
}

```

I was trying changing to data frame and dropping the `id` value with the `nan` value and changing to dictionary back but couldn't get the intended result.

```
 my_updated_dict = pd.DataFrame(my_dict ).dropna().to_dict('list')

```

Answer: 
You can use `update()` to overwrite the value of the key, then you can try:

```
my_dict.update({'fields':[x for x in my_dict['fields'] if np.nan not in x.values()]})

```

Returning:

```
{'fields': [{'id': 1.0, 'name': 'aaa', 'type': 'string'},
  {'id': 3.0, 'name': 'eee', 'type': 'string'},
  {'id': 4.0, 'name': 'ccc', 'type': 'string'}],
 'type': 'struct'}

```
Considering the dictionary `json`

```
import numpy as np

json = {'fields': [{'id': 1.0, 'name': 'aaa', 'type': 'string'},
                     {'id': 3.0, 'name': 'eee', 'type': 'string'},
                        {'id': np.nan, 'name': 'bbb', 'type': 'string'},
                            {'id': 4.0, 'name': 'ccc', 'type': 'string'},
                                {'id': np.nan, 'name': 'ddd', 'type': 'string'}],
                                    'type': 'struct'}

```

In order to remove the parts where `id` is `np.nan`, one can use a list comprehension with [`numpy.isnan`](https://numpy.org/doc/stable/reference/generated/numpy.isnan.html) as follows

```
json['fields'] = [x for x in json['fields'] if not np.isnan(x['id'])]

[Out]:

{'fields': [{'id': 1.0, 'name': 'aaa', 'type': 'string'},
            {'id': 3.0, 'name': 'eee', 'type': 'string'},
            {'id': 4.0, 'name': 'ccc', 'type': 'string'}],
 'type': 'struct'}

```