{"id":2734,"date":"2026-08-04T06:12:58","date_gmt":"2026-08-03T23:12:58","guid":{"rendered":"https:\/\/sumberlaba.com\/index.php\/2026\/08\/04\/data-cleaning-with-pandas-a-practical-python-tutorial\/"},"modified":"2026-08-04T06:12:58","modified_gmt":"2026-08-03T23:12:58","slug":"data-cleaning-with-pandas-a-practical-python-tutorial","status":"publish","type":"post","link":"https:\/\/sumberlaba.com\/index.php\/2026\/08\/04\/data-cleaning-with-pandas-a-practical-python-tutorial\/","title":{"rendered":"Data Cleaning with Pandas: A Practical Python Tutorial"},"content":{"rendered":"<p>&#8220;`html<\/p>\n<h1>Data Cleaning with Pandas: A Practical Python Tutorial<\/h1>\n<p>Raw data is messy. It contains missing values, duplicates, and incorrect data types that can ruin your analysis. Pandas, Python\u2019s most popular data library, provides simple and efficient methods to clean datasets in just a few lines of code.<\/p>\n<p>This tutorial assumes you have a DataFrame named <code>df<\/code>. Start by importing pandas with <code>import pandas as pd<\/code>. We\u2019ll explore four essential data cleaning tasks you\u2019ll use almost every day.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/via.placeholder.com\/800x600\/4a90d9\/ffffff?text=how%20to%20use%20pandas%20for%20data%20cleaning\" alt=\"Article illustration\" style=\"display:block;margin:20px auto;max-width:100%;height:auto;border-radius:8px;\" \/><\/p>\n<h2>1. Handle Missing Values<\/h2>\n<p>Missing values appear as <code>NaN<\/code>. First, detect them with <code>df.isnull().sum()<\/code>. Then decide whether to remove or fill them:<\/p>\n<ul>\n<li><code>df.dropna()<\/code> \u2014 remove all rows containing missing values<\/li>\n<li><code>df.fillna(0)<\/code> \u2014 fill missing values with 0<\/li>\n<li><code>df['price'].fillna(df['price'].mean())<\/code> \u2014 fill a column with its mean<\/li>\n<\/ul>\n<h2>2. Remove Duplicate Rows<\/h2>\n<p>Duplicates skew your counts and averages. Check them with <code>df.duplicated().sum()<\/code>. Remove them with <code>df.drop_duplicates()<\/code>. To target specific columns, pass a <code>subset<\/code>:<\/p>\n<p><code>df.drop_duplicates(subset=['email'], keep='first')<\/code><\/p>\n<h2>3. Convert Data Types<\/h2>\n<p>Wrong types cause errors and slow down analysis. Convert them using <code>astype()<\/code> and <code>pd.to_datetime()<\/code>:<\/p>\n<ul>\n<li><code>df['age'] = df['age'].astype(int)<\/code><\/li>\n<li><code>df['price'] = df['price'].astype(float)<\/code><\/li>\n<li><code>df['date'] = pd.to_datetime(df['date'])<\/code><\/li>\n<\/ul>\n<h2>4. Clean Columns and Filter Rows<\/h2>\n<p>Rename columns for consistency, drop unused ones, and keep only the rows you need:<\/p>\n<ul>\n<li><code>df.rename(columns={'old': 'new'}, inplace=True)<\/code><\/li>\n<li><code>df.drop(columns=['unused'], inplace=True)<\/code><\/li>\n<li><code>df_filtered = df[df['age'] &gt; 18]<\/code><\/li>\n<li><code>df['name'] = df['name'].str.strip().str.title()<\/code><\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Data cleaning doesn\u2019t have to be painful. With pandas, you can handle missing values, duplicates, type issues, and column cleanup in a few commands. Master these basics, and your data will be analysis-ready in no time.<\/p>\n<p>&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`html Data Cleaning with Pandas: A Practical Python Tutorial Raw data is messy. It contains missing values, duplicates, and incorrect data types that can ruin your analysis. Pandas, Python\u2019s most popular data library, provides simple and efficient methods to clean datasets in just a few lines of code. This tutorial assumes you have a DataFrame &hellip; <\/p>\n","protected":false},"author":2716,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-2734","post","type-post","status-publish","format-standard","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/users\/2716"}],"replies":[{"embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/comments?post=2734"}],"version-history":[{"count":0,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/posts\/2734\/revisions"}],"wp:attachment":[{"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/media?parent=2734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/categories?post=2734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumberlaba.com\/index.php\/wp-json\/wp\/v2\/tags?post=2734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}