pandas fill inf code example
Example 1: pandas dataframe replace inf
df.replace([np.inf, -np.inf], np.nan)
Example 2: check if dataframe contains infinity
df.replace([np.inf, -np.inf], np.nan).dropna(subset=["col1", "col2"], how="all")
Example 3: remove nans and infs python
df.replace([np.inf, -np.inf], np.nan).dropna(axis=1)