Pandas has a very nice feature to export our dataframes to a list of dicts via pd.to_dict('records').
For example:
d = pd.DataFrame({'a':[1,2,3], 'b':['a', 'b', None]})
d.to_dict('records')
returns
[{'a': 1, 'b': 'a'}, {'a': 2, 'b': 'b'}, {'a': 3, 'b': None}]
For my use case, I would prefer the following entry:
[{'a': 1, 'b': 'a'}, {'a': 2, 'b': 'b'}, {'a': 3}]
where you can see the key of b is removed from the third entry. This is default behavior in R when using jsonlite, and am wondering how I would remove keys with missing values from each entry.