I have a data frame that contains a column called identifiers and i need to change this to a json list.
list_identifiers=df['identifier'].tolist() listjson=json.dumps(list_identifiers)
It looks like some Nan values are invalid and i get this error when i am running a query with the list.
DETAIL: Token "NaN" is invalid.
CONTEXT: JSON data, line 1: ...E00B8KQN827", "US0530151036", "CA82509L1076", NaN...
Can you help me remove the NaN from the json list? Thanks a lot!
3
Answers
For removing NAN from a list, did you try numpy.nan object?
I mean do it this way:
Furthermore, as I know there is also a dropna method in Pandas library you can use:
pandas
to_json
should convert "NaN" to "null" for you, which are JSON compatible: