Pandas (page 6 of 9) |
We can check for missing values (np.nan or null) by running pd.isnull(), which returns True for missing and False for non-missing. Alternatively, we can sum of number of the missing values by executing pd.isnull().sum() or pd.notnull().sum() to find the number of non-null data points.
We can drop the nulls by executing my_df.dropna() to drop the rows or my_df.dropna(axis=1) to drop the columns. Alternatively, we can fill the missing values with other values by executing df.fillna(0), which fills the missing values with 0 (substitute 0 with appropriate value).
We can replace values (e.g., my_df['col1'] = my_df['col1'].replace(np.inf, 3) replaces the np.inf's in col1 with 3s.