Created
December 31, 2021 11:04
-
-
Save bruno-uy/fe5a91b38bf83ac635ecf544e7457566 to your computer and use it in GitHub Desktop.
Export pandas DataFrame to a dict with None instead of nan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
df = pd.DataFrame({"A": [1, 2, 3], "B": [1.2, np.NaN, 3.4]}) | |
result = ( | |
df | |
.replace([np.nan], [None], regex=False) | |
.to_dict(orient="records") | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment