{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Ibrahim Salami",
  "title_listed": "EDA in Public (Part 1): Cleaning and Exploring Sales Data with Pandas",
  "keywords": "",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/",
  "publish_date": "2025-12-12",
  "corpus_stage": "",
  "notes": "",
  "id": "19dd9eb49a70",
  "collected_at": "2026-10-02T12:04:38",
  "title": "EDA in Public (Part 1): Cleaning and Exploring Sales Data with Pandas | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Programming](https://towardsdatascience.com/category/programming/)\n# EDA in Public (Part 1): Cleaning and Exploring Sales Data with Pandas\nLearn how to clean messy CSVs, summarize data, and visualize basic trends in e-commerce sales.\n[Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\nDecember 12, 202510 min read\n![Exploratory Data Analysis with Pandas](../images/000.jpg)\nImage by Author. Created with Gemini\nHey everyone! Welcome to the start of a major data journey that I’m calling “EDA in Public.” For those who know me, I believe the best way to learn anything is to tackle a real-world problem and share the entire messy process — including mistakes, victories, and everything in between. If you’ve been looking to level up your Pandas and data analysis skills, this is the series for you.\nWe’re going to act as data analysts for a fictional, mid-sized e-commerce company I’ll call **NovaShop**. They handed us a raw, messy sales CSV and asked a simple question: “How are we doing?”\nThe goal of **Part 1** is foundational: we’ll clean this challenging e-commerce dataset, explore its basic structure, and master the core EDA skills in Pandas that every data scientist uses on a daily basis. This series is structured to take you from a **beginner** (Part 1) to an **advanced** data analyst (Part 3), so feel free to jump in wherever you’re at.\nBefore we jump into the code, let’s nail down our core motivation. For NovaShop, we need to answer some simple, yet powerful questions: Which products drive the most revenue? Which countries generate the most sales? Let’s find out.\nLearn this step by step with the interactive [Computer Science](https://roadmap.sh/computer-science) roadmap.\n## Dataset Overview: Unpacking the Sales Data\nTo start our analysis for NovaShop, we’ll be using the [**UCI Online Retail Dataset**](https://archive.ics.uci.edu/dataset/352/online+retail)[.](https://archive.ics.uci.edu/dataset/352/online+retail) This is a great, highly realistic, non-streamlined dataset that captures all transactions for a UK-based non-store online retail company between late 2010 and late 2011. \nThis dataset is licensed under a [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) (CC BY 4.0) license.\nThis allows for the sharing and adaptation of the datasets for any purpose, provided that the appropriate credit is given.\nThe dataset contains over half a million rows, and it’s full of the kinds of anomalies you encounter in the real world — missing values, negative numbers, and inconsistent text formatting. This is exactly what we want!\nHere are the eight key columns we’ll be working with, and what they tell us from a business perspective:\n  * **InvoiceNo:** This is theInvoice number. A unique 6-digit number assigned to each transaction. If the code starts with ‘C’, it indicates a **cancellation** (a return).\n  * **StockCode/Product code** : A unique 5-digit code assigned to each distinct product.\n  * **Description:** The name of the item. This often needs cleaning (extra spaces, inconsistent cases).\n  * **Quantity:** Number of items purchased. How many units were involved per transaction? Can be **negative** for returns.\n  * **InvoiceDate:** The date and time of the transaction. This is essential for time-series analysis later on.\n  * **UnitPrice:** Product price per unit in Sterling (GBP). The price of one item. It can sometimes be 0 or negative due to errors/free items.\n  * **CustomerID:** A unique 5-digit number assigned to each registered customer. Crucially, this is often missing, meaning we have many transactions from guests.\n  * **Country:** Name of the country where the customer resides. This would be great for segmenting international sales.\n\n\nLet’s take a quick peek at the first few rows to see what we’re dealing with. This is the output of `df.head()`:\nLet’s import the dataset into Pandas and see how many rows we’re dealing with.\npython\n\n```\nimport pandas as pd\nimport numpy as np\ndf = pd.read_csv(‘Online Retail.csv’)\ndf.shape\n```\n\n**Output:**\nmarkup\n\n```\n(541909, 8)\n```\n\nThat’s quite a lot of rows. I might have to slice the rows a bit.\n## Data Loading and Slicing: Dealing with Volume\nFor Part 1, we’re going to take a **10% random sample** of the full dataset. This gives us a much more manageable size — around 54,000 rows — while maintaining the characteristics of the original data. This is a common and practical technique when dealing with Big Data environments or when focusing on prototyping.\npython\n\n```\n# Data Loading and Slicing\nFILE_PATH = ‘Online Retail.csv’\nSAMPLE_FRACTION = 0.1 # We will sample 10% of the data\nfull_df = pd.read_csv(FILE_PATH, encoding=’unicode_escape’)\n\n# Take a random 10% sample for faster processing in Part 1\ndf = full_df.sample(frac=SAMPLE_FRACTION, random_state=42).reset_index(drop=True)\n```\n\nNow, let’s check out the shape again using the `df.shape`\n**Output:**\nmarkup\n\n```\n(54191, 8)\n```\n\nPerfect! Now we can begin.\n## Initial Data Inspection: Getting Our Hands Dirty\nMy first step will be to discover what we're cleaning. I need to answer these questions\n  * What does the dataset contain?\n  * What are the data types and non-null counts?\n  * What do the numbers look like?\n\n\n### Visual Check: df.head() and df.tail()\nLooking at the first and last few rows, I could confirm a few things:\n  * **Cancellations & Returns:** I happened to notice some `InvoiceNo` values starting with **'C'** , and the corresponding `Quantity` is negative. This confirms returns are included, and for revenue analysis, I'll need to separate or exclude them.\n  * **Missingness:** I could visually see `NaN` values in the `CustomerID` column, confirming the mass of guest transactions.\n  * **Inconsistent Text:** I checked the Description column for whitespaces. Based on the small sample I got, I couldn’t really tell. But it doesn’t hurt to address them when I go into data cleaning. I might also keep the capitalisation consistent. It's always best practice to **strip all leading/trailing whitespace** from all string columns to prevent subtle errors when grouping.\n  * I also noticed some capitalisation inconsistencies in the Country column. I spotted a country named EIRE. It probably means Ireland, might need to change that.\n\n\n### What Are the Data Types and Non-Null Counts? (`.info()`)\nThe next essential step is to check the structure using the `.info()` method. This tells me the data type of each column and, most importantly, how many non-null (not missing) values we have.\n_Key Findings_\n  * **Missing Values:** After taking our 10% sample, I could see a massive gap in `CustomerID`. Roughly 25% of the customer IDs are missing. I also noticed a few hundred missing values in `Description` that I’ll need to address.\n  * **Data Types:** The `InvoiceDate` column is still listed as an `object` (string) type. Gotta convert this to a proper Pandas `datetime` object.`CustomerID` is also currently a **float** , likely because it contains those `NaN` values! This is a little detail I’ll need to remember if I ever want to use it as a true integer ID.\n\n\n### What Do the Numbers Look Like? (`.describe()`)\nNext, I used `.describe()` to get a quick statistical summary of all the numerical columns (`Quantity` and `UnitPrice`).\n  * **Quantity**(`Quantity`)**:** The minimum quantity is **-2472**. This confirms that returns exist, but the scale of those minimum points suggests an extreme outlier transaction. For basic sales analysis, I might need to filter out these negative numbers and potentially the extreme positive and negative outliers.\n  * **Unit Price**(`UnitPrice`)**:** The minimum price is **0**. This means some products were given away for free or are placeholder entries. Since a product should have a positive price in a normal sale, filtering out any rows where `UnitPrice` is zero or less is always best practice to calculate revenue accurately.\n\n\nBased on these quick inspections performed.This data is far from clean. We have massive missingness, incorrect data types, highly problematic negative/zero values in our core numerical columns, and text inconsistencies to tackle.\n## Handling Missing Values\nNow that we know where our data is missing, we can begin discussing strategies for handling null values. I’m mostly concerned with `Description` and `CustomerID`.\n### Missing Descriptions\nThe `Description` tells us what product was sold, so losing it renders the transaction meaningless. In our sample, less than 1% of the rows have descriptions missing. Dropping those rows completely makes sense, as they are useless for analysis at the product level.\npython\n\n```\n# Drop rows where the Description is missing\ndf.dropna(subset=['Description'], inplace=True)\n# checking for null counts\ndf['Description'].isnull().sum()\n```\n\n**Output:**\nmarkup\n\n```\nnp.int64(0)\n```\n\nAlright, perfect! All null values are gone.\n### Missing Customer IDs\nThe missing `CustomerID`s (around 25% of our sample) are a much bigger deal. If I drop all of them, I’ll lose almost a quarter of our sales data, which will give NovaShop a dangerously skewed view of its total revenue.\nFor simple revenue and product analysis (the goal of Part 1), I don’t really need the `CustomerID`. We can proceed with the analysis on all rows _even without_ an ID. We only need the ID if we plan on doing customer segmentation (like RFM analysis), which I’ll save for Part 2!\n## Data Type Conversion and Duplicate Removal\nNow that we’ve handled the missing descriptions, the next two immediate issues are dealing with fully duplicated rows and fixing our essential `InvoiceDate` column.\n### Fixing the Invoice Date Type\nRemember how `.info()` showed `InvoiceDate` as a string (`object`)? We need to fix this immediately so Pandas knows how to sort and aggregate our data chronologically.\npython\n\n```\n# Convert InvoiceDate from object (string) to datetime\ndf[‘InvoiceDate’] = pd.to_datetime(df[‘InvoiceDate’])\n```\n\n### Removing Duplicates\nIf two rows are identical across _all_ columns, they are duplicates and will artificially inflate our sales numbers. Let’s check for them and remove them.\npython\n\n```\n# Remove Duplicates\nnum_duplicates = df.duplicated().sum()\nprint(f”Found {num_duplicates} fully duplicated rows.”)\n```\n\n**Output:**\nmarkup\n\n```\nFound 62 fully duplicated rows\n```\n\nLet’s drop them\npython\n\n```\n# Remove duplicates, keeping the first instance\ndf.drop_duplicates(inplace=True)\nprint(f”Dataframe size after removing duplicates: {len(df)} rows.”)\n```\n\nOutput:\nmarkup\n\n```\nDataframe size after removing duplicates: 53980 rows.\n```\n\n## Filtering Out Returns and Errors\nOur `.describe()` method showed us some serious red flags: negative quantities (returns) and zero/negative unit prices (errors/free items). For Part 1, we want to calculate **net revenue from sales** , so we must filter this noise out.\n### Handling Negative Quantities and Prices\nWe will keep only the transactions where:\n  * `Quantity` is strictly greater than zero (filtering out all returns and cancellations).\n  * `UnitPrice` is strictly greater than zero (filtering out errors and free items).\n\n\npython\n\n```\n# Filter: Keep only transactions where Quantity is positive (i.e., sales, not returns)\ndf = df[df[‘Quantity’] > 0]\n\n# Filter: Keep only transactions where UnitPrice is positive (i.e., not free or an error)\ndf = df[df[‘UnitPrice’] > 0]\nprint(f”Dataframe size after filtering: {len(df)} rows.”)\n```\n\n**Output**\nmarkup\n\n```\nDataframe size after filtering: 52933 rows.\n```\n\n### Cleaning Text Columns\nFinally, let’s tackle those text standardization issues we spotted visually, like the `EIRE` country code and any potential hidden whitespace in `Description`.\n  * **Strip Whitespace:** We use `.str.strip()` to remove leading/trailing spaces from both `Description` and `Country`.\n  * **Standardize Country:** We manually map inconsistencies like ‘EIRE’ to ‘Ireland’.\n\n\npython\n\n```\n# Cleaning Text Columns\n# Clean Description and Country columns\ndf[‘Description’] = df[‘Description’].str.strip()\ndf[‘Country’] = df[‘Country’].str.strip()\n\n# Handle specific country name inconsistencies\n# EIRE is a common inconsistency in this dataset for Ireland\ndf[‘Country’].replace(‘EIRE’, ‘Ireland’, inplace=True)\nprint(“Text columns cleaned and standardized.”)\n```\n\n## Feature Engineering & First Insight\nThe data is now clean. Now we can finally start asking the fun questions. The single most important metric for any sales dataset is revenue. Since our original data only has `Quantity` and `UnitPrice`, we need to engineer the **Revenue** column ourselves.\n### Feature Engineering: Creating the `Revenue` Column\nRevenue for a transaction is simply the number of items sold multiplied by the price of each item.\npython\n\n```\ndf[‘Revenue’] = df[‘Quantity’] * df[‘UnitPrice’]\n```\n\n### First Insight: Which Countries Drive Revenue?\nLet’s use our clean data to answer NovaShop’s question: **“Which countries are driving our sales?”**  \nWe’ll use a powerful three-step combination:\n  * **Group** by the `Country` column.\n  * **Aggregate** (sum) the `Revenue` within each group.\n  * **Sort** the results from highest revenue to lowest.\n\n\npython\n\n```\n# Group by Country, sum the Revenue, and sort for the top 10\ntop_countries = df.groupby(‘Country’)[‘Revenue’].sum().sort_values(ascending=False).head(10)\nprint(“\\n — — Top 10 Countries by Revenue (GBP) — -”)\nprint(top_countries)\n```\n\n**Output:**\nmarkup\n\n```\n--- Top 10 Countries by Revenue (GBP) ---CountryUnited Kingdom 941268.661Netherlands 27435.830EIRE 26066.000France 23645.330Germany 22389.510Australia 12429.990Spain 5600.900Switzerland 5483.890Hong Kong 3597.850Belgium 3593.510Name: Revenue, dtype: float64\n```\n\n  \nThe output for this typically shows a massive dominance by the **United Kingdom**. This is expected since the company is UK-based. The next several countries give us a quick roadmap of where NovaShop’s international focus should be.\n## Conclusion\nWe did it. We took a raw, half-a-million-row dataset, sliced it for manageability, battled missing values, fixed data types, filtered out errors, and calculated our first key business metric. The hard, foundational work is done.\nHere’s a quick recap of what we conquered in Part 1:\n  * **Data Vetting:** We used `.head()`, `.info()`, and .`describe()` to identify crucial issues like the negative prices/quantities, missing Customer IDs, and the incorrect datetime format.\n  * **Data Cleaning:** We systematically removed nulls and duplicates, converted `InvoiceDate` to a proper `datetime` object, and filtered out non-sale transactions (returns and free items).\n  * **Feature Engineering:** We created the critical `Revenue` column.\n  * **First Insight:** We generated the Top 10 Countries by Revenue for NovaShop, giving them their first actionable data point from the clean set.\n\n\nThe clean dataset is now primed for more sophisticated analysis. In Part 2, we’re going to dive deep into [**Product Analysis and Time-Series Decomposition.**](https://towardsdatascience.com/eda-in-public-part-2-product-deep-dive-time-series-analysis-in-pandas/) We’ll figure out which items are the true money-makers and analyse how sales volume changes hour-by-hour and month-by-month.\nI’m excited to keep going! If you enjoyed this article. Feel free to let me know on any of these channels. Your feedback will mean a lot to me.  \n  \n[Medium](https://medium.com/@ibbysalam)\n[LinkedIn](https://www.linkedin.com/in/ibrahim-salami-059863228/)\n[Twitter](https://x.com/IbbySalam)\n[YouTube](https://www.youtube.com/@ibbysalam)  \n\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](../images/body-542334df68a32cd56c4a.jpeg)\nWritten By\n## [Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\n[See all from Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\n[Data Analytics](https://towardsdatascience.com/tag/data-analytics/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Eda In Python](https://towardsdatascience.com/tag/eda-in-python/)[Exploratory Data Analysis](https://towardsdatascience.com/tag/exploratory-data-analysis/)[Python](https://towardsdatascience.com/tag/python/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F&title=EDA%20in%20Public%20\\(Part%201\\)%3A%20Cleaning%20and%20Exploring%20Sales%20Data%20with%C2%A0Pandas)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F&title=EDA%20in%20Public%20\\(Part%201\\)%3A%20Cleaning%20and%20Exploring%20Sales%20Data%20with%C2%A0Pandas)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F&text=EDA%20in%20Public%20\\(Part%201\\)%3A%20Cleaning%20and%20Exploring%20Sales%20Data%20with%C2%A0Pandas)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/001.jpg)](https://towardsdatascience.com/why-should-we-bother-with-quantum-computing-in-ml/)\n## [Why Should We Bother with Quantum Computing in ML?](https://towardsdatascience.com/why-should-we-bother-with-quantum-computing-in-ml/)\n[Quantum Computing](https://towardsdatascience.com/category/quantum-computing/)\nQuantum Machine Learning principles\n[Erika Gomes-Gonçalves](https://towardsdatascience.com/author/erika.g.goncalves/)\nOctober 22, 202514 min read\n  * [![](../images/002.jpg)](https://towardsdatascience.com/using-function-decorators-in-python-21fcb2e37e5c/)\n## [Using Function Decorators in Python](https://towardsdatascience.com/using-function-decorators-in-python-21fcb2e37e5c/)\n[](https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/)\nLearn how to extend the functionalities of function by using function decorators In this article,...\n[Wei-Meng Lee](https://towardsdatascience.com/author/weimenglee/)\nJune 1, 20215 min read\n  * [![](../images/003.jpg)](https://towardsdatascience.com/korean-actor-recommendation-using-machine-learning-e7ba26e3926/)\n## [How to Find Korean Actors for Binge-Watching with Machine Learning](https://towardsdatascience.com/korean-actor-recommendation-using-machine-learning-e7ba26e3926/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLet Me Find You The Closest Actors to Your Favourite Korean Actor\n[Intan Dea Yutami](https://towardsdatascience.com/author/intandeay/)\nDecember 6, 20216 min read\n  * [![](../images/004.jpeg)](https://towardsdatascience.com/pandas-minesweeper-101-d330cc2658ee/)\n## [Pandas Minesweeper 101](https://towardsdatascience.com/pandas-minesweeper-101-d330cc2658ee/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLookout for these hurdles before diving deep into pandas\n[Sahithya Swaminathan](https://towardsdatascience.com/author/sahithyaswaminathan/)\nNovember 27, 20205 min read\n  * [![](../images/005.jpg)](https://towardsdatascience.com/creating-the-cityspire-app-my-journey-ff31fc9990ce/)\n## [Creating the CitySpire App: My Journey](https://towardsdatascience.com/creating-the-cityspire-app-my-journey-ff31fc9990ce/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nMy Journey About the Project In the last eight weeks, I was a part of...\n[Sweta Sengupta](https://towardsdatascience.com/author/ssengupta801/)\nApril 28, 20217 min read\n  * [![](../images/006.gif)](https://towardsdatascience.com/oktoberfest-quick-analysis-using-pandas-matplotlib-and-plotly-79778367a4c/)\n## [Oktoberfest : Quick analysis using Pandas, Matplotlib, and Plotly](https://towardsdatascience.com/oktoberfest-quick-analysis-using-pandas-matplotlib-and-plotly-79778367a4c/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nOktoberfest 2019 has started! Oktoberfest is the world's largest beer festival and is held annually in Munich since 1810. It lasts...\n[Amanda Iglesias Moreno](https://towardsdatascience.com/author/amandaiglesiasmoreno/)\nSeptember 22, 201910 min read\n  * [![](../images/007.png)](https://towardsdatascience.com/inventory-management-for-retail-deterministic-demand-311682c02518/)\n## [Inventory Management for Retail – Deterministic Demand](https://towardsdatascience.com/inventory-management-for-retail-deterministic-demand-311682c02518/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nBuild a simple model to simulate the impact of several replenishment rules on inventory and ordering costs.\n[Samir Saci](https://towardsdatascience.com/author/s-saci95/)\nOctober 5, 20211 min read\n  * [![](../images/008.jpg)](https://towardsdatascience.com/how-i-learned-tableau-in-1-day-8db80c167f9d/)\n## [How I Learned Tableau in 1 Day](https://towardsdatascience.com/how-i-learned-tableau-in-1-day-8db80c167f9d/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nFrom installing the software to delivering a dashboard\n[Arunn Thevapalan](https://towardsdatascience.com/author/arunnthevapalan/)\nJune 24, 20204 min read\n  * [![](../images/009.jpeg)](https://towardsdatascience.com/remove-punctuation-pandas-3e461efe9584/)\n## [How To Remove Punctuation From Pandas](https://towardsdatascience.com/remove-punctuation-pandas-3e461efe9584/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nShowcasing different ways for eliminating punctuation from pandas DataFrame columns\n[Giorgos Myrianthous](https://towardsdatascience.com/author/gmyrianthous/)\nApril 12, 20225 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500) Productivity Tips, Data Career Insights, and Other Recent Must-Reads ](https://towardsdatascience.com/productivity-tips-data-career-insights-and-other-recent-must-reads-5c47eb7a2fe0/ \"Productivity Tips, Data Career Insights, and Other Recent Must-Reads\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "metadata": {
    "title": "EDA in Public (Part 1): Cleaning and Exploring Sales Data with Pandas | Towards Data Science",
    "description": "Learn how to clean messy CSVs, summarize data, and visualize basic trends in e-commerce sales.",
    "keywords": null,
    "author": "Ibrahim Salami",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "EDA in Public (Part 1): Cleaning and Exploring Sales Data with Pandas",
    "og:description": "Learn how to clean messy CSVs, summarize data, and visualize basic trends in e-commerce sales.",
    "og:url": "https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2025/12/EDA-with-Pandas-img.jpg",
    "og:image:width": "1971",
    "og:image:height": "1075",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Ibrahim Salami",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "10 min read",
    "article:published_time": "2025-12-12T08:20:06.000Z",
    "article:modified_time": "2025-12-12T08:20:06.000Z",
    "article:author": "https://towardsdatascience.com/author/ibrahim.salami/"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 202,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_000.txt",
      "chars": 86
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_001.txt",
      "chars": 12
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_002.txt",
      "chars": 316
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_003.txt",
      "chars": 11
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_004.txt",
      "chars": 153
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_005.txt",
      "chars": 12
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_006.txt",
      "chars": 109
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_007.txt",
      "chars": 115
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_008.txt",
      "chars": 31
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_009.txt",
      "chars": 149
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_010.txt",
      "chars": 54
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_011.txt",
      "chars": 293
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_012.txt",
      "chars": 44
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_013.txt",
      "chars": 368
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_014.txt",
      "chars": 49
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_015.txt",
      "chars": 229
    },
    {
      "language": "txt",
      "file": "attachments/19dd9eb49a70/code/block_016.txt",
      "chars": 258
    }
  ],
  "images": [
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:45:41Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:45:41Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:45:41Z"
    },
    {
      "status": "http_404",
      "url": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "src": "https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500",
      "alt": "",
      "downloaded": false,
      "discovery": "saved_markdown",
      "retried_at": "2026-10-20T17:45:41Z"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/@ibbysalam",
      "kind": "channel_reference",
      "status": "reference_only"
    },
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/programming/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/ibrahim.salami/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/eda-in-public-part-2-product-deep-dive-time-series-analysis-in-pandas/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-analytics/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/eda-in-python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/exploratory-data-analysis/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/why-should-we-bother-with-quantum-computing-in-ml/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/quantum-computing/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/erika.g.goncalves/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/using-function-decorators-in-python-21fcb2e37e5c/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/weimenglee/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/computer-science"
    },
    {
      "type": "external",
      "href": "https://archive.ics.uci.edu/dataset/352/online+retail"
    },
    {
      "type": "external",
      "href": "https://creativecommons.org/licenses/by/4.0/legalcode"
    },
    {
      "type": "external",
      "href": "https://medium.com/@ibbysalam"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/in/ibrahim-salami-059863228/"
    },
    {
      "type": "external",
      "href": "https://x.com/IbbySalam"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/@ibbysalam"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=EDA+in+Public+%28Part+1%29%3A+Cleaning+and+Exploring+Sales+Data+with%C2%A0Pandas&u=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=EDA+in+Public+%28Part+1%29%3A+Cleaning+and+Exploring+Sales+Data+with%C2%A0Pandas&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=EDA+in+Public+%28Part+1%29%3A+Cleaning+and+Exploring+Sales+Data+with%C2%A0Pandas&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh"
    },
    {
      "type": "external",
      "href": "https://insightmediagroup.io/creator-network"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-20T17:26:12Z",
  "source_url": "https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "源页面未重新核验:http_403；已按保留正文补采图片",
  "repair_error": "",
  "actual_video_files": [],
  "expected_saved_body_images": 4,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Programming](https://towardsdatascience.com/category/programming/)\n# EDA in Public (Part 1): Cleaning and Exploring Sales Data with Pandas\nLearn how to clean messy CSVs, summarize data, and visualize basic trends in e-commerce sales.\n[Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\nDecember 12, 202510 min read\n![Exploratory Data Analysis with Pandas](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/12/EDA-with-Pandas-img.jpg)\nImage by Author. Created with Gemini\nHey everyone! Welcome to the start of a major data journey that I’m calling “EDA in Public.” For those who know me, I believe the best way to learn anything is to tackle a real-world problem and share the entire messy process — including mistakes, victories, and everything in between. If you’ve been looking to level up your Pandas and data analysis skills, this is the series for you.\nWe’re going to act as data analysts for a fictional, mid-sized e-commerce company I’ll call **NovaShop**. They handed us a raw, messy sales CSV and asked a simple question: “How are we doing?”\nThe goal of **Part 1** is foundational: we’ll clean this challenging e-commerce dataset, explore its basic structure, and master the core EDA skills in Pandas that every data scientist uses on a daily basis. This series is structured to take you from a **beginner** (Part 1) to an **advanced** data analyst (Part 3), so feel free to jump in wherever you’re at.\nBefore we jump into the code, let’s nail down our core motivation. For NovaShop, we need to answer some simple, yet powerful questions: Which products drive the most revenue? Which countries generate the most sales? Let’s find out.\nLearn this step by step with the interactive [Computer Science](https://roadmap.sh/computer-science) roadmap.\n## Dataset Overview: Unpacking the Sales Data\nTo start our analysis for NovaShop, we’ll be using the [**UCI Online Retail Dataset**](https://archive.ics.uci.edu/dataset/352/online+retail)[.](https://archive.ics.uci.edu/dataset/352/online+retail) This is a great, highly realistic, non-streamlined dataset that captures all transactions for a UK-based non-store online retail company between late 2010 and late 2011. \nThis dataset is licensed under a [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode) (CC BY 4.0) license.\nThis allows for the sharing and adaptation of the datasets for any purpose, provided that the appropriate credit is given.\nThe dataset contains over half a million rows, and it’s full of the kinds of anomalies you encounter in the real world — missing values, negative numbers, and inconsistent text formatting. This is exactly what we want!\nHere are the eight key columns we’ll be working with, and what they tell us from a business perspective:\n  * **InvoiceNo:** This is theInvoice number. A unique 6-digit number assigned to each transaction. If the code starts with ‘C’, it indicates a **cancellation** (a return).\n  * **StockCode/Product code** : A unique 5-digit code assigned to each distinct product.\n  * **Description:** The name of the item. This often needs cleaning (extra spaces, inconsistent cases).\n  * **Quantity:** Number of items purchased. How many units were involved per transaction? Can be **negative** for returns.\n  * **InvoiceDate:** The date and time of the transaction. This is essential for time-series analysis later on.\n  * **UnitPrice:** Product price per unit in Sterling (GBP). The price of one item. It can sometimes be 0 or negative due to errors/free items.\n  * **CustomerID:** A unique 5-digit number assigned to each registered customer. Crucially, this is often missing, meaning we have many transactions from guests.\n  * **Country:** Name of the country where the customer resides. This would be great for segmenting international sales.\n\n\nLet’s take a quick peek at the first few rows to see what we’re dealing with. This is the output of `df.head()`:\nLet’s import the dataset into Pandas and see how many rows we’re dealing with.\npython\n\n```\nimport pandas as pd\nimport numpy as np\ndf = pd.read_csv(‘Online Retail.csv’)\ndf.shape\n```\n\n**Output:**\nmarkup\n\n```\n(541909, 8)\n```\n\nThat’s quite a lot of rows. I might have to slice the rows a bit.\n## Data Loading and Slicing: Dealing with Volume\nFor Part 1, we’re going to take a **10% random sample** of the full dataset. This gives us a much more manageable size — around 54,000 rows — while maintaining the characteristics of the original data. This is a common and practical technique when dealing with Big Data environments or when focusing on prototyping.\npython\n\n```\n# Data Loading and Slicing\nFILE_PATH = ‘Online Retail.csv’\nSAMPLE_FRACTION = 0.1 # We will sample 10% of the data\nfull_df = pd.read_csv(FILE_PATH, encoding=’unicode_escape’)\n\n# Take a random 10% sample for faster processing in Part 1\ndf = full_df.sample(frac=SAMPLE_FRACTION, random_state=42).reset_index(drop=True)\n```\n\nNow, let’s check out the shape again using the `df.shape`\n**Output:**\nmarkup\n\n```\n(54191, 8)\n```\n\nPerfect! Now we can begin.\n## Initial Data Inspection: Getting Our Hands Dirty\nMy first step will be to discover what we're cleaning. I need to answer these questions\n  * What does the dataset contain?\n  * What are the data types and non-null counts?\n  * What do the numbers look like?\n\n\n### Visual Check: df.head() and df.tail()\nLooking at the first and last few rows, I could confirm a few things:\n  * **Cancellations & Returns:** I happened to notice some `InvoiceNo` values starting with **'C'** , and the corresponding `Quantity` is negative. This confirms returns are included, and for revenue analysis, I'll need to separate or exclude them.\n  * **Missingness:** I could visually see `NaN` values in the `CustomerID` column, confirming the mass of guest transactions.\n  * **Inconsistent Text:** I checked the Description column for whitespaces. Based on the small sample I got, I couldn’t really tell. But it doesn’t hurt to address them when I go into data cleaning. I might also keep the capitalisation consistent. It's always best practice to **strip all leading/trailing whitespace** from all string columns to prevent subtle errors when grouping.\n  * I also noticed some capitalisation inconsistencies in the Country column. I spotted a country named EIRE. It probably means Ireland, might need to change that.\n\n\n### What Are the Data Types and Non-Null Counts? (`.info()`)\nThe next essential step is to check the structure using the `.info()` method. This tells me the data type of each column and, most importantly, how many non-null (not missing) values we have.\n_Key Findings_\n  * **Missing Values:** After taking our 10% sample, I could see a massive gap in `CustomerID`. Roughly 25% of the customer IDs are missing. I also noticed a few hundred missing values in `Description` that I’ll need to address.\n  * **Data Types:** The `InvoiceDate` column is still listed as an `object` (string) type. Gotta convert this to a proper Pandas `datetime` object.`CustomerID` is also currently a **float** , likely because it contains those `NaN` values! This is a little detail I’ll need to remember if I ever want to use it as a true integer ID.\n\n\n### What Do the Numbers Look Like? (`.describe()`)\nNext, I used `.describe()` to get a quick statistical summary of all the numerical columns (`Quantity` and `UnitPrice`).\n  * **Quantity**(`Quantity`)**:** The minimum quantity is **-2472**. This confirms that returns exist, but the scale of those minimum points suggests an extreme outlier transaction. For basic sales analysis, I might need to filter out these negative numbers and potentially the extreme positive and negative outliers.\n  * **Unit Price**(`UnitPrice`)**:** The minimum price is **0**. This means some products were given away for free or are placeholder entries. Since a product should have a positive price in a normal sale, filtering out any rows where `UnitPrice` is zero or less is always best practice to calculate revenue accurately.\n\n\nBased on these quick inspections performed.This data is far from clean. We have massive missingness, incorrect data types, highly problematic negative/zero values in our core numerical columns, and text inconsistencies to tackle.\n## Handling Missing Values\nNow that we know where our data is missing, we can begin discussing strategies for handling null values. I’m mostly concerned with `Description` and `CustomerID`.\n### Missing Descriptions\nThe `Description` tells us what product was sold, so losing it renders the transaction meaningless. In our sample, less than 1% of the rows have descriptions missing. Dropping those rows completely makes sense, as they are useless for analysis at the product level.\npython\n\n```\n# Drop rows where the Description is missing\ndf.dropna(subset=['Description'], inplace=True)\n# checking for null counts\ndf['Description'].isnull().sum()\n```\n\n**Output:**\nmarkup\n\n```\nnp.int64(0)\n```\n\nAlright, perfect! All null values are gone.\n### Missing Customer IDs\nThe missing `CustomerID`s (around 25% of our sample) are a much bigger deal. If I drop all of them, I’ll lose almost a quarter of our sales data, which will give NovaShop a dangerously skewed view of its total revenue.\nFor simple revenue and product analysis (the goal of Part 1), I don’t really need the `CustomerID`. We can proceed with the analysis on all rows _even without_ an ID. We only need the ID if we plan on doing customer segmentation (like RFM analysis), which I’ll save for Part 2!\n## Data Type Conversion and Duplicate Removal\nNow that we’ve handled the missing descriptions, the next two immediate issues are dealing with fully duplicated rows and fixing our essential `InvoiceDate` column.\n### Fixing the Invoice Date Type\nRemember how `.info()` showed `InvoiceDate` as a string (`object`)? We need to fix this immediately so Pandas knows how to sort and aggregate our data chronologically.\npython\n\n```\n# Convert InvoiceDate from object (string) to datetime\ndf[‘InvoiceDate’] = pd.to_datetime(df[‘InvoiceDate’])\n```\n\n### Removing Duplicates\nIf two rows are identical across _all_ columns, they are duplicates and will artificially inflate our sales numbers. Let’s check for them and remove them.\npython\n\n```\n# Remove Duplicates\nnum_duplicates = df.duplicated().sum()\nprint(f”Found {num_duplicates} fully duplicated rows.”)\n```\n\n**Output:**\nmarkup\n\n```\nFound 62 fully duplicated rows\n```\n\nLet’s drop them\npython\n\n```\n# Remove duplicates, keeping the first instance\ndf.drop_duplicates(inplace=True)\nprint(f”Dataframe size after removing duplicates: {len(df)} rows.”)\n```\n\nOutput:\nmarkup\n\n```\nDataframe size after removing duplicates: 53980 rows.\n```\n\n## Filtering Out Returns and Errors\nOur `.describe()` method showed us some serious red flags: negative quantities (returns) and zero/negative unit prices (errors/free items). For Part 1, we want to calculate **net revenue from sales** , so we must filter this noise out.\n### Handling Negative Quantities and Prices\nWe will keep only the transactions where:\n  * `Quantity` is strictly greater than zero (filtering out all returns and cancellations).\n  * `UnitPrice` is strictly greater than zero (filtering out errors and free items).\n\n\npython\n\n```\n# Filter: Keep only transactions where Quantity is positive (i.e., sales, not returns)\ndf = df[df[‘Quantity’] > 0]\n\n# Filter: Keep only transactions where UnitPrice is positive (i.e., not free or an error)\ndf = df[df[‘UnitPrice’] > 0]\nprint(f”Dataframe size after filtering: {len(df)} rows.”)\n```\n\n**Output**\nmarkup\n\n```\nDataframe size after filtering: 52933 rows.\n```\n\n### Cleaning Text Columns\nFinally, let’s tackle those text standardization issues we spotted visually, like the `EIRE` country code and any potential hidden whitespace in `Description`.\n  * **Strip Whitespace:** We use `.str.strip()` to remove leading/trailing spaces from both `Description` and `Country`.\n  * **Standardize Country:** We manually map inconsistencies like ‘EIRE’ to ‘Ireland’.\n\n\npython\n\n```\n# Cleaning Text Columns\n# Clean Description and Country columns\ndf[‘Description’] = df[‘Description’].str.strip()\ndf[‘Country’] = df[‘Country’].str.strip()\n\n# Handle specific country name inconsistencies\n# EIRE is a common inconsistency in this dataset for Ireland\ndf[‘Country’].replace(‘EIRE’, ‘Ireland’, inplace=True)\nprint(“Text columns cleaned and standardized.”)\n```\n\n## Feature Engineering & First Insight\nThe data is now clean. Now we can finally start asking the fun questions. The single most important metric for any sales dataset is revenue. Since our original data only has `Quantity` and `UnitPrice`, we need to engineer the **Revenue** column ourselves.\n### Feature Engineering: Creating the `Revenue` Column\nRevenue for a transaction is simply the number of items sold multiplied by the price of each item.\npython\n\n```\ndf[‘Revenue’] = df[‘Quantity’] * df[‘UnitPrice’]\n```\n\n### First Insight: Which Countries Drive Revenue?\nLet’s use our clean data to answer NovaShop’s question: **“Which countries are driving our sales?”**  \nWe’ll use a powerful three-step combination:\n  * **Group** by the `Country` column.\n  * **Aggregate** (sum) the `Revenue` within each group.\n  * **Sort** the results from highest revenue to lowest.\n\n\npython\n\n```\n# Group by Country, sum the Revenue, and sort for the top 10\ntop_countries = df.groupby(‘Country’)[‘Revenue’].sum().sort_values(ascending=False).head(10)\nprint(“\\n — — Top 10 Countries by Revenue (GBP) — -”)\nprint(top_countries)\n```\n\n**Output:**\nmarkup\n\n```\n--- Top 10 Countries by Revenue (GBP) ---CountryUnited Kingdom 941268.661Netherlands 27435.830EIRE 26066.000France 23645.330Germany 22389.510Australia 12429.990Spain 5600.900Switzerland 5483.890Hong Kong 3597.850Belgium 3593.510Name: Revenue, dtype: float64\n```\n\n  \nThe output for this typically shows a massive dominance by the **United Kingdom**. This is expected since the company is UK-based. The next several countries give us a quick roadmap of where NovaShop’s international focus should be.\n## Conclusion\nWe did it. We took a raw, half-a-million-row dataset, sliced it for manageability, battled missing values, fixed data types, filtered out errors, and calculated our first key business metric. The hard, foundational work is done.\nHere’s a quick recap of what we conquered in Part 1:\n  * **Data Vetting:** We used `.head()`, `.info()`, and .`describe()` to identify crucial issues like the negative prices/quantities, missing Customer IDs, and the incorrect datetime format.\n  * **Data Cleaning:** We systematically removed nulls and duplicates, converted `InvoiceDate` to a proper `datetime` object, and filtered out non-sale transactions (returns and free items).\n  * **Feature Engineering:** We created the critical `Revenue` column.\n  * **First Insight:** We generated the Top 10 Countries by Revenue for NovaShop, giving them their first actionable data point from the clean set.\n\n\nThe clean dataset is now primed for more sophisticated analysis. In Part 2, we’re going to dive deep into [**Product Analysis and Time-Series Decomposition.**](https://towardsdatascience.com/eda-in-public-part-2-product-deep-dive-time-series-analysis-in-pandas/) We’ll figure out which items are the true money-makers and analyse how sales volume changes hour-by-hour and month-by-month.\nI’m excited to keep going! If you enjoyed this article. Feel free to let me know on any of these channels. Your feedback will mean a lot to me.  \n  \n[Medium](https://medium.com/@ibbysalam)\n[LinkedIn](https://www.linkedin.com/in/ibrahim-salami-059863228/)\n[Twitter](https://x.com/IbbySalam)\n[YouTube](https://www.youtube.com/@ibbysalam)  \n\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657709013_9ddcph.jpeg)\nWritten By\n## [Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\n[See all from Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\n[Data Analytics](https://towardsdatascience.com/tag/data-analytics/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Eda In Python](https://towardsdatascience.com/tag/eda-in-python/)[Exploratory Data Analysis](https://towardsdatascience.com/tag/exploratory-data-analysis/)[Python](https://towardsdatascience.com/tag/python/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F&title=EDA%20in%20Public%20\\(Part%201\\)%3A%20Cleaning%20and%20Exploring%20Sales%20Data%20with%C2%A0Pandas)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F&title=EDA%20in%20Public%20\\(Part%201\\)%3A%20Cleaning%20and%20Exploring%20Sales%20Data%20with%C2%A0Pandas)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-1-cleaning-exploring-sales-data-with-pandas%2F&text=EDA%20in%20Public%20\\(Part%201\\)%3A%20Cleaning%20and%20Exploring%20Sales%20Data%20with%C2%A0Pandas)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/10/9CA5BC8C-A164-42C3-9DD0-E157DD5617A4-scaled-1.jpg)](https://towardsdatascience.com/why-should-we-bother-with-quantum-computing-in-ml/)\n## [Why Should We Bother with Quantum Computing in ML?](https://towardsdatascience.com/why-should-we-bother-with-quantum-computing-in-ml/)\n[Quantum Computing](https://towardsdatascience.com/category/quantum-computing/)\nQuantum Machine Learning principles\n[Erika Gomes-Gonçalves](https://towardsdatascience.com/author/erika.g.goncalves/)\nOctober 22, 202514 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/06/0BlwFDPvkVfT4_5LK-scaled.jpg)](https://towardsdatascience.com/using-function-decorators-in-python-21fcb2e37e5c/)\n## [Using Function Decorators in Python](https://towardsdatascience.com/using-function-decorators-in-python-21fcb2e37e5c/)\n[](https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/)\nLearn how to extend the functionalities of function by using function decorators In this article,...\n[Wei-Meng Lee](https://towardsdatascience.com/author/weimenglee/)\nJune 1, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/12/0fHJ7otgFOsTuuaSn-scaled.jpg)](https://towardsdatascience.com/korean-actor-recommendation-using-machine-learning-e7ba26e3926/)\n## [How to Find Korean Actors for Binge-Watching with Machine Learning](https://towardsdatascience.com/korean-actor-recommendation-using-machine-learning-e7ba26e3926/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLet Me Find You The Closest Actors to Your Favourite Korean Actor\n[Intan Dea Yutami](https://towardsdatascience.com/author/intandeay/)\nDecember 6, 20216 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/1iSGkbcIJ0vrmtz_KztuSBw.jpeg)](https://towardsdatascience.com/pandas-minesweeper-101-d330cc2658ee/)\n## [Pandas Minesweeper 101](https://towardsdatascience.com/pandas-minesweeper-101-d330cc2658ee/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nLookout for these hurdles before diving deep into pandas\n[Sahithya Swaminathan](https://towardsdatascience.com/author/sahithyaswaminathan/)\nNovember 27, 20205 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/0umJIKOHBs36_beC7-scaled.jpg)](https://towardsdatascience.com/creating-the-cityspire-app-my-journey-ff31fc9990ce/)\n## [Creating the CitySpire App: My Journey](https://towardsdatascience.com/creating-the-cityspire-app-my-journey-ff31fc9990ce/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nMy Journey About the Project In the last eight weeks, I was a part of...\n[Sweta Sengupta](https://towardsdatascience.com/author/ssengupta801/)\nApril 28, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/09/1JWAlu8JEk5mi3Q1ASLrXUw.gif)](https://towardsdatascience.com/oktoberfest-quick-analysis-using-pandas-matplotlib-and-plotly-79778367a4c/)\n## [Oktoberfest : Quick analysis using Pandas, Matplotlib, and Plotly](https://towardsdatascience.com/oktoberfest-quick-analysis-using-pandas-matplotlib-and-plotly-79778367a4c/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nOktoberfest 2019 has started! Oktoberfest is the world's largest beer festival and is held annually in Munich since 1810. It lasts...\n[Amanda Iglesias Moreno](https://towardsdatascience.com/author/amandaiglesiasmoreno/)\nSeptember 22, 201910 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/10/1GrAHw2d9Sa5qShf-cKhYYA.png)](https://towardsdatascience.com/inventory-management-for-retail-deterministic-demand-311682c02518/)\n## [Inventory Management for Retail – Deterministic Demand](https://towardsdatascience.com/inventory-management-for-retail-deterministic-demand-311682c02518/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nBuild a simple model to simulate the impact of several replenishment rules on inventory and ordering costs.\n[Samir Saci](https://towardsdatascience.com/author/s-saci95/)\nOctober 5, 20211 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/06/0dMtMGi4Glif1hejp-scaled.jpg)](https://towardsdatascience.com/how-i-learned-tableau-in-1-day-8db80c167f9d/)\n## [How I Learned Tableau in 1 Day](https://towardsdatascience.com/how-i-learned-tableau-in-1-day-8db80c167f9d/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nFrom installing the software to delivering a dashboard\n[Arunn Thevapalan](https://towardsdatascience.com/author/arunnthevapalan/)\nJune 24, 20204 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/10iC83tkRiYOx2YxI0dgfeg-scaled.jpeg)](https://towardsdatascience.com/remove-punctuation-pandas-3e461efe9584/)\n## [How To Remove Punctuation From Pandas](https://towardsdatascience.com/remove-punctuation-pandas-3e461efe9584/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nShowcasing different ways for eliminating punctuation from pandas DataFrame columns\n[Giorgos Myrianthous](https://towardsdatascience.com/author/gmyrianthous/)\nApril 12, 20225 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/4970/image?etag=1780565225463&width=500&height=500) Productivity Tips, Data Career Insights, and Other Recent Must-Reads ](https://towardsdatascience.com/productivity-tips-data-career-insights-and-other-recent-must-reads-5c47eb7a2fe0/ \"Productivity Tips, Data Career Insights, and Other Recent Must-Reads\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/3660/image?etag=1780176246070&width=500&height=500) Does Your Company Have a Data Strategy? ](https://towardsdatascience.com/does-your-company-have-a-data-strategy-e8944dbec4ae/ \"Does Your Company Have a Data Strategy?\")\n\n\n",
  "body_base_path": "attachments/19dd9eb49a70/pages/",
  "body_markdown_path": "attachments/19dd9eb49a70/pages/archived-body.md",
  "local_html": "attachments/19dd9eb49a70/pages/archived-body.html",
  "body_source": "prior_capture"
}