4 Ways to Replace NaN Values with Zero’s in Pandas DataFrame

Depending on the scenario, you may use either of the 4 methods below in order to replace NaN values with zero’s in pandas DataFrame: (1) For a single column using pandas:  df[‘DataFrame Column’] = df[‘DataFrame Column’].fillna(0) (2) For a single column using numpy: df[‘DataFrame Column’] = df[‘DataFrame Column’].replace(np.nan, 0) (3) For an entire DataFrame using …

How to Convert Strings to Floats in Pandas DataFrame

Need to convert strings to floats in pandas DataFrame? Depending on the scenario, you may use either of the following two methods in order to convert strings to floats in pandas DataFrame: (1) astype(float) method df[‘DataFrame Column’] = df[‘DataFrame Column’].astype(float) (2) to_numeric method df[‘DataFrame Column’] = pd.to_numeric(df[‘DataFrame Column’],errors=’coerce’) Want to see how to apply those two methods …

How to get the Descriptive Statistics for Pandas DataFrame

Need to get the descriptive statistics for pandas DataFrame? If so, you can use the following template to get the descriptive statistics for your DataFrame:   DataFrame.describe(df[‘DataFrame Field’])   In the next section, I’ll show you the steps to derive the descriptive statistics using an example. Steps to get the Descriptive Statistics for Pandas DataFrame Step 1: Collect …

Example of Confusion Matrix in Python

In this tutorial, I’ll show you a full example of a Confusion Matrix in Python. Topics to be reviewed: Creating a Confusion Matrix using pandas Displaying the Confusion Matrix using seaborn  Getting additional stats via pandas_ml Working with non-numerical data Creating a Confusion Matrix in Python using Pandas To start, here is the data-set that we’ll …