I have a DF that looks something like:
A B C D E
1 1 NaN 1 1
NaN 2 3 4 NaN
When I do:
df.to_json(orient='records')
I get something like
[{"A":1,"B":1,"C":null,"D":1,"E":1},{"A":null,"B":2,"C":3,"D":4,"E":null}]
Is there anyway to get it to ignore anything that has NaN and show something like:
[{"A":1,"B":1,"D":1,"E":1},{"B":2,"C":3,"D":4}]
Can I do this using pandas?
[dict(zip(x.index.get_level_values(1),x)) for _,x in df.replace('NAN',np.nan).stack().groupby(level=0)]