1 the background: use the pandas and django, djangorestframework in json and dataframe transformation to complete the Response data () returns the mistakes

ValueError: Floating point values out of range do not match JSON

3 My solution: Replace the special characters with nan or None

# 1 Converts the original df special symbol to nan
df.replace(to_replace=r'(^\s*$)|--', value=np.nan, regex=True, inplace=True)
# 2 Change nan to None
df = df.where(df.notnull(), None)


# note:
You can also do it in one step
df.replace(to_replace=r'(^\s*$)|--', value=None, regex=True, inplace=True)
Copy the code