Duplicate rows often occur due to repeated form submissions, database re-syncs, or ETL joining errors.
keep Parameter Options:keep='first' (Default): Retains the first occurrence and drops subsequent duplicates.keep='last': Retains the last occurrence and drops earlier duplicates.keep=False: Drops ALL occurrences of duplicates (keeping only strictly unique rows)..astype())Often numbers (like "₹4500" or phone numbers "9876543210") are imported as generic object (string) types. To perform calculations, cast them to proper datatypes:
pd.to_numeric()When a column contains dirty strings (like "N/A" or "invalid"), .astype(float) crashes with a ValueError. pd.to_numeric(errors='coerce') gracefully converts bad values into NaN:
category)For text columns with limited unique values (e.g. Gender, State, Department), converting from object to category reduces memory usage by up to 90% and speeds up grouping:
df.drop_duplicates(keep=False)?pd.to_numeric(series, errors='coerce') do when encountering unparseable text?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Dropping & Filling Missing Values (dropna, fillna) | Applying Custom Functions (apply, map, applymap) |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.