How to Count Duplicates in Pandas DataFrame

You can count duplicates in pandas DataFrame by using this method: df.pivot_table(index=[‘DataFrame Column’], aggfunc=’size’) Next, I’ll review the following 3 cases to demonstrate how to count duplicates in pandas DataFrame: (1) under a single column (2) across multiple columns (3) when having NaN values in the DataFrame 3 Cases of Counting Duplicates in Pandas DataFrame …

4 Methods to Round Values in Pandas DataFrame

Depending on the scenario, you may use either of the 4 methods below in order to round values in pandas DataFrame: (1) Round to specific decimal places – Single DataFrame column df[‘DataFrame column’].round(decimals=number of decimal places needed) (2) Round up – Single DataFrame column df[‘DataFrame column’].apply(np.ceil) (3) Round down – Single DataFrame column df[‘DataFrame column’].apply(np.floor) …

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 …