{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Ibrahim Salami",
  "title_listed": "EDA in Public (Part 3): RFM Analysis for Customer Segmentation in Pandas",
  "keywords": "",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/eda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas/",
  "publish_date": "2026-01-01",
  "corpus_stage": "",
  "notes": "",
  "id": "fc5bdb5647f7",
  "collected_at": "2026-10-02T11:59:15",
  "title": "EDA in Public (Part 3): RFM Analysis for Customer Segmentation in 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[Data Science](https://towardsdatascience.com/category/data-science/)\n# EDA in Public (Part 3): RFM Analysis for Customer Segmentation in Pandas\nHow to build, score, and interpret RFM segments step by step\n[Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\nJanuary 1, 202612 min read\n![Exploratory Data Analysis with Pandas](../images/000.jpg)\nImage by Author. Created with Gemini\nWelcome back! If you’ve been following along, we’ve come a long way. In [**Part 1**](https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/), we did the “dirty work” of cleaning and prepping.\nIn [**Part 2**](https://towardsdatascience.com/eda-in-public-part-2-product-deep-dive-time-series-analysis-in-pandas/), we zoomed out to a high-altitude view of NovaShop’s world — spotting the big storms (high-revenue countries) and the seasonal patterns (the massive Q4 rush).\nBut here’s the thing: a business doesn’t actually sell to “months” or “countries.” It sells to **human beings**.\nIf you treat every customer exactly the same, you’re making two very expensive mistakes:\n  * **Over-discounting:** Giving a “20% off” coupon to someone who was already reaching for their wallet.\n  * **Ignoring the “Quiet” Ones:** Failing to notice when a formerly loyal customer stops visiting, until they’ve been gone for six months and it’s too late to win them back.\n\n\n**The Solution? Behavioural Segmentation.**\nInstead of guessing, we’re going to use the data to let the customers tell us who they are. We do this using the gold standard of retail analytics: **RFM Analysis**.\n  * **Recency (R):** How recently did they buy? (Are they still engaged with us?)\n  * **Frequency (F):** How often do they buy? (Are they loyal, or was it a one-off?)\n  * **Monetary (M):** How much do they spend? (What is their total business impact?)\n\n\nBy the end of this part, we’ll move beyond “Top 10 Products” and actually assign a specific, actionable **Label** to every single customer in NovaShop’s database.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) roadmap.\n## Data Preparation: The “Missing ID” Pivot\nBefore we can start scoring, we have to address a decision we made back in Part 1.\nIf you remember our **Initial Inspection** , we noticed that about 25% of our rows were missing a `CustomerID`. At the time, we made a strategic business decision to _keep those rows. We needed them to calculate the_ accurate total revenue and see which products were popular overall.\nFor RFM analysis, the rules change. You cannot track behavior without a consistent identity. We can’t know how “frequent” a customer is if we don’t know who they are!\nSo, our first step in Part 3 is to isolate our “Trackable Universe” by filtering for rows where a `CustomerID` exists.\n## Engineering the RFM Metrics\nNow that we have a dataset where every row is linked to a specific person, we need to aggregate all their individual transactions into three summary numbers: Recency, Frequency, and Monetary.\n### Defining the Snapshot Date\nBefore calculating RFM, we need a **reference point in time** , commonly called the _snapshot date_.\nHere, we take the most recent transaction date in the dataset and add one day. This snapshot date represents the moment at which we’re evaluating customer behaviour.\npython\n\n```\nsnapshot_date = df['InvoiceDate'].max() + dt.timedelta(days=1)\n```\n\nWe added one day, so customers who bought on the most recent date still have a Recency value of 1 day, not 0. This keeps the metric intuitive and avoids edge-case problems.\n### Aggregating Transactions at the Customer Level\npython\n\n```\nrfm = df.groupby(‘CustomerID’).agg({\n‘InvoiceDate’: lambda x: (snapshot_date — x.max()).days,\n‘InvoiceNo’: ‘nunique’,\n‘Revenue’: ‘sum’\n})\n```\n\nEach row in our dataset represents a single transaction. To calculate RFM, we need to **collapse these transactions into one row per customer**.\nWe do this by grouping the data by `CustomerID` and applying different aggregation functions:\n  * **Recency** : For each customer, we find their most recent purchase date and calculate how many days have passed since then.\n  * **Frequency:** We count the number of unique invoices associated with each customer. This tells us how often they’ve made purchases.\n  * **Monetary** : We sum the total revenue generated by each customer across all transactions.\n\n\n### Renaming Columns for Clarity\npython\n\n```\nrfm.rename(columns={\n'InvoiceDate': 'Recency',\n'InvoiceNo': 'Frequency',\n'Revenue': 'Monetary'\n}, inplace=True)py\n```\n\nThe aggregation step keeps the original column names, which can be confusing. Renaming them makes the dataframe immediately readable and aligns it with standard RFM terminology.\nNow each column clearly answers a business question:\n  * **Recency** → How recently did the customer purchase?\n  * **Frequency** → How often do they purchase?\n  * **Monetary** → How much revenue do they generate?\n\n\n## Inspecting the Result\npython\n\n```\nprint(rfm.head())\n```\n\nThe final `rfm` dataframe contains **one row per customer** , with three intuitive metrics summarizing their behavior. \n**Output:**\n![](../images/001.jpg)\nLet’s walk through this the way we would with NovaShop in a real conversation.\n> “When was the last time this customer bought from us?”\nThat’s exactly what **Recency** answers.\nTake **Customer 12347** :\n  * Recency = **2**\n  * Translation: _“This customer bought something just two days ago.”_\n\n\nThey’re fresh. They remember the brand. They’re still engaged.\nNow compare that to **Customer 12346** :\n  * Recency = **326**\n  * Translation: _“They haven’t bought anything in almost a year.”_\n\n\nEven though this customer spent a lot in the past, they’re currently silent.\n**From NovaShop’s perspective:** Recency tells us who’s still listening and who might need a nudge (or a wake-up call).\n> “Is this a one-time buyer or someone who keeps coming back?”\nThat’s where **Frequency** comes in.\nLook again at **Customer 12347** :\n  * Frequency = **7**\n  * They didn’t just buy once — they came back again and again.\n\n\nNow look at several others:\n  * Frequency = **1**\n  * One purchase, then gone.\n\n\n**From a business perspective,** frequency separates casual shoppers from loyal customers.\n> “Who actually brings in the money?”\nThat’s the **Monetary** column.  \nAnd this is where things get interesting.\n**Customer 12346** :\n  * Monetary = **£77,183.60**\n  * Frequency = **1**\n  * Recency = **326**\n\n\nThis tells a very specific story:\nA single, very large order… a long time ago… and nothing since.\nNow compare that to **Customer 12347** :\n  * Lower total spend\n  * Multiple purchases\n  * Very recent activity\n\n\n**Important insight for NovaShop:** A “high-value” customer in the past isn’t necessarily a valuable customer _today_.\n### Why This View Changes the Conversation\nIf NovaShop only looked at total revenue, they might focus all their attention on customers like **12346**.\nBut RFM shows us that:\n  * Some customers spent a lot once and disappeared\n  * Some spend less but stay loyal\n  * Some are active _right now_ and ready to be engaged\n\n\nThis output helps NovaShop stop guessing and start prioritizing:\n  * Who should get retention emails?\n  * Who needs reactivation campaigns?\n  * Who is already loyal and should be rewarded?\n\n\nRight now, these are still raw numbers.\nIn the next step, we’ll **rank and score** these customers, so NovaShop doesn’t have to interpret rows manually. Instead, they’ll see clear segments like:\n  * _Champions_\n  * _Loyal Customers_\n  * _At-Risk_\n  * _Lost_\n\n\nThat’s where this becomes a real decision-making tool — not just a dataframe.\n## Turning RFM Numbers Into Meaningful Customer Segments\nAt this stage, NovaShop has a table full of numbers. Useful — but not exactly decision-friendly.\nA marketing team can’t realistically scan hundreds or thousands of rows asking:\n  * _Is a Recency of 19 good or bad?_\n  * _Is Frequency = 2 impressive?_\n  * _How much Monetary value is “high”?_\n\n\nOur goal is to rank customers relative to one another and turn raw values into scores _._\n### Step 1: Ranking Customers by Each RFM Metric\nInstead of treating Recency, Frequency, and Monetary as absolute values, we look at where each customer **stands compared to everyone else**.\n  * Customers with **more recent purchases** should score higher\n  * Customers who **buy more often** should score higher\n  * Customers who **spend more** should score higher\n\n\nIn practice, we do this by splitting each metric into **quantiles** (usually 4 or 5 buckets).\nHowever, there’s a small real-world wrinkle. This is something I came across while working on this project\nIn transactional datasets, it’s common to see:\n  * Many customers with the same Frequency (e.g. one-time buyers)\n  * Highly skewed Monetary values\n  * Small samples where quantile binning can fail\n\n\nTo keep things robust and readable, we’ll wrap the scoring logic in a small helper function.\npython\n\n```\ndef rfm_score(series, ascending=True, n_bins=5):\n# Rank the values to ensure uniqueness\nranked = series.rank(method=’first’, ascending=ascending)\n\n# Use pd.qcut on the ranks to assign bins\nreturn pd.qcut(\nranked,\nq=n_bins,\nlabels=range(1, n_bins+1)\n).astype(int)\n```\n\nTo explain what’s going on here:\n  * We’re creating a helper function that turns a raw numeric column into a clean **RFM score** using quantile-based binning.\n  * First, the values are ranked.So, instead of binning the raw values directly, we rank them first. This step guarantees **unique ordering** , even when many customers share the same value (a common issue in RFM data). \n  * The `ascending` flag lets us flip the logic depending on the metric — for example, lower recency is better, while higher frequency and monetary values are better.\n  * Next, we’re applying **quantile-based binning.**`qcut` splits the ranked values into `n_bins` equally sized groups. Each customer is assigned a score from **1 to 5** (by default), where the score represents their relative position within the distribution.\n  * Finally, the results will be converted to integers for easy use in analysis and segmentation.\n\n\nIn short, this function provides a **robust and reusable way** to score RFM metrics without running into duplicate bin edge errors — and without overcomplicating the logic.\n### Step 2: Applying the Scores\nNow we can score each metric cleanly and consistently:\npython\n\n```\n# Assign R, F, M scores\nrfm['R_Score'] = rfm_score(rfm['Recency'], ascending=False) # Recent purchases = high score\nrfm['F_Score'] = rfm_score(rfm['Frequency']) # More frequent = high score\nrfm['M_Score'] = rfm_score(rfm['Monetary']) # Higher spend = high score\n```\n\nThe only special case here is **Recency** :\n  * Lower values mean more recent activity\n  * So we reverse the ranking with `ascending=False`\n  * Everything else follows the natural “higher is better” rule.\n\n\n#### What This Means for NovaShop\nInstead of seeing this:\nmarkup\n\n```\nRecency = 326Frequency = 1Monetary = 77,183.60\n```\n\nNovaShop now sees something like:\nmarkup\n\n```\nR = 1, F = 1, M = 5\n```\n\nThat’s instantly more interpretable:\n  * Not recent\n  * Not frequent\n  * High spender (historically)\n\n\n### Step 3: Creating a Combined RFM Score\nNow we combine these three scores into a single RFM code:\npython\n\n```\nrfm['RFM_Score'] = (\nrfm['R_Score'].astype(str) +\nrfm['F_Score'].astype(str) +\nrfm['M_Score'].astype(str)\n)\n```\n\nThis produces values like:\n  * **555** → Best customers\n  * **155** → High spenders who haven’t returned\n  * **111** → Customers who are likely gone\n\n\nEach customer now carries a compact behavioral fingerprint. And we’re not done yet.\n## Translating RFM Scores Into Customer Segments\nRaw scores are nice, but let’s be honest: **no marketing manager wants to look at 555, 154, or 311 all day**.\nNovaShop needs **labels that make sense at a glance**. That’s where RFM segments come in.\n### Step 1: Defining Segments\nUsing RFM scores, we can classify customers into meaningful categories. Here’s a common approach:\n  * **Champions:** Top Recency, top Frequency, top Monetary (555) — your best customers\n  * **Loyal Customers:** Regular buyers, may not be spending the most, but keep coming back\n  * **Big Spenders:** High Monetary, but not necessarily recent or frequent\n  * **At-Risk:** Used to buy, but haven’t returned recently\n  * **Lost:** Low scores in all three metrics — likely disengaged\n  * **Promising / New:** Recent customers with lower frequency or monetary spend\n\n\nThis transforms **abstract numbers** into a **narrative** that marketing and management can act on.\n### Step 2: Mapping Scores to Segments\nHere’s an example using simple conditional logic:\npython\n\n```\ndef rfm_segment(row):\nif row['R_Score'] >= 4 and row['F_Score'] >= 4 and row['M_Score'] >= 4:\nreturn 'Champions'\nelif row['F_Score'] >= 4:\nreturn 'Loyal Customers'\nelif row['M_Score'] >= 4:\nreturn 'Big Spenders'\nelif row['R_Score'] <= 2:\nreturn 'At-Risk'\nelse:\nreturn 'Others'\nrfm['Segment'] = rfm.apply(rfm_segment, axis=1)\n```\n\nNow each customer has a **human-readable label** , making it immediately actionable.\nLet’s review our results using `rfm.head()`  \n\n![](../images/body-2c11e609ee30eb2bb37c.jpg)\n### Step 3: Turning Segments into Strategy\nWith labeled segments, NovaShop can:\n  * **Reward Champions** → Exclusive deals, loyalty points\n  * **Re-engage Big Spenders & At-Risk customers** → Personalized emails or discounts\n  * **Focus marketing wisely** → Don’t waste effort on customers who are truly lost\n\n\nThis is the moment where data becomes strategy.\n## What NovaShop Should Do Next (Key Takeaways & Recommendations)\nAt the start of this analysis, NovaShop had a familiar problem:  \n**A lot of transactional data, but limited clarity on customer behaviour**.\nBy applying the RFM framework, we’ve turned raw purchase history into a clear, structured view of who NovaShop’s customers are — and how they behave.\nNow let’s talk about what to actually do with it.\n### 1. Protect and Reward Your Best Customers\n**Champions** and **Loyal Customers** are already doing what every business wants:\n  * They buy recently\n  * They buy often\n  * They generate consistent revenue\n\n\nThese customers don’t need heavy discounts — they need recognition.\n**Recommended actions:**\n  * Early access to sales\n  * Loyalty points or VIP tiers\n  * Personalized thank-you emails\n\n\n> _The goal here isn’t acquisition, it’s retention._\n### 2. Re-Engage High-Value Customers Before They’re Lost\nThe most dangerous segment for NovaShop isn’t “Lost” customers.  \nIt’s **At-Risk** and **Big Spenders**.\nThese customers:\n  * Have shown clear value in the past\n  * But haven’t purchased recently\n  * Are one step away from churning completely\n\n\n**Recommended actions:**\n  * Targeted win-back campaigns\n  * Personalized offers (not blanket discounts)\n  * Reminder emails tied to past purchase behavior\n\n\n> _Winning back an existing customer is almost always cheaper than acquiring a new one._\n### 3. Don’t Over-Invest in Truly Lost Customers\nSome customers will inevitably churn. RFM helps NovaShop identify those customers early and avoid spending ad budget, discounts and marketing effort on users who are unlikely to return. This isn’t about being cold — it’s about being **efficient**.\n### 4. Use RFM as a Living Framework, Not a One-Off Analysis\nThe real power of RFM comes when it’s:\n  * Recomputed monthly or quarterly\n  * Integrated into dashboards\n  * Used to track movement between segments over time\n\n\nFor NovaShop, this means asking questions like:\n  * _How many At-Risk customers became Loyal this month?_\n  * _Are Champions increasing or shrinking?_\n  * _Which campaigns actually move customers up the ladder?_\n\n\nRFM turns customer behaviour into something **measurable and trackable**.\n## Final Thoughts: Closing the EDA in Public Series\nWhen I started this _EDA in Public_ series, I wasn’t trying to build the perfect analysis or demonstrate advanced techniques. I wanted to slow down and share how I actually think when working with real data. Not the polished version, but the messy, iterative process that usually stays hidden.\nThis project began with a noisy CSV and a lot of open questions. Along the way, there were small issues that only surfaced once I paid closer attention — dates stored as strings, assumptions that didn’t quite hold up, metrics that needed context before they made sense. Working through those moments in public was uncomfortable at times, but also genuinely valuable. Each correction made the analysis stronger and more honest.\nOne thing this process reinforced for me is that most meaningful insights don’t come from complexity. They come from slowing down, structuring the data properly, and asking better questions. By the time I reached the RFM analysis, the value wasn’t in the formulas themselves — it was in what they forced me to confront. A customer who spent a lot once isn’t necessarily valuable today. Recency matters. Frequency matters. And none of these metrics mean much in isolation.\nEnding the series with RFM felt deliberate. It sits at the point where technical work meets business thinking, where tables turn into conversations and numbers turn into decisions. It’s also where exploratory analysis stops being purely descriptive and starts becoming practical. At that stage, the goal is no longer just to understand the data, but to decide what to do next.\nDoing this work in public changed how I approach analysis. Writing things out forced me to explain my reasoning, question my assumptions, and be comfortable showing imperfect work. It reminded me that EDA isn’t a checklist you rush through — it’s a dialogue with the data. Sharing that dialogue makes you more thoughtful and more accountable.\nThis may be the final part of the _EDA in Public_ series, but it doesn’t feel like an endpoint. Everything here could evolve into dashboards, automated pipelines, or deeper customer analysis. \nAnd if you’re a founder, analyst, or team working with customer or sales data and trying to make sense of it, this kind of exploratory work is often where the biggest clarity comes from. These are exactly the kinds of problems I enjoy working through — slowly, thoughtfully, and with the business context in mind.\nIf you’re documenting your own analyses, I’d love to see how you approach it. And if you’re wrestling with similar questions in your data and want to talk through them, feel free to reach out on any of the platforms below. Good data conversations usually start there.\nThanks for following along!\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## 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[Deep Dives](https://towardsdatascience.com/tag/deep-dives/)[Exploratory Data Analysis](https://towardsdatascience.com/tag/exploratory-data-analysis/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Pandas](https://towardsdatascience.com/tag/pandas/)[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-3-rfm-analysis-for-customer-segmentation-in-pandas%2F&title=EDA%20in%20Public%20\\(Part%203\\)%3A%20RFM%20Analysis%20for%20Customer%20Segmentation%20in%C2%A0Pandas)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas%2F&title=EDA%20in%20Public%20\\(Part%203\\)%3A%20RFM%20Analysis%20for%20Customer%20Segmentation%20in%C2%A0Pandas)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas%2F&text=EDA%20in%20Public%20\\(Part%203\\)%3A%20RFM%20Analysis%20for%20Customer%20Segmentation%20in%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/002.png)](https://towardsdatascience.com/instacart-users-segmentation-and-market-basket-analysis-d88378f75f73/)\n## [Instacart Users Segmentation and Market Basket Analysis](https://towardsdatascience.com/instacart-users-segmentation-and-market-basket-analysis-d88378f75f73/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nXin Yu, Yingyuan (Valerie) Zhang, Yutong (Grace) Zhu\n[Yingyuan (Valerie) Zhang](https://towardsdatascience.com/author/yz6378/)\nOctober 12, 20205 min read\n  * [![](../images/003.jpeg)](https://towardsdatascience.com/introduction-to-applied-linear-algebra-vectors-29ff7e0539/)\n## [Introduction to Applied Linear Algebra: Vectors](https://towardsdatascience.com/introduction-to-applied-linear-algebra-vectors-29ff7e0539/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nThis article gives an introduction to vectors, vector operations and their application in the field of data science.\n[Deniz Tuzsus](https://towardsdatascience.com/author/deniz.tuzsus/)\nNovember 25, 20215 min read\n  * [![](../images/004.jpeg)](https://towardsdatascience.com/creating-a-machine-learning-model-with-sql-81d843a5307c/)\n## [Creating a Machine Learning Model with SQL](https://towardsdatascience.com/creating-a-machine-learning-model-with-sql-81d843a5307c/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBuild an ML model using SQL on Google Big Query\n[Anuj Syal](https://towardsdatascience.com/author/syal-anuj/)\nNovember 12, 20215 min read\n  * [![](../images/005.jpg)](https://towardsdatascience.com/how-to-build-a-machine-learning-demo-in-2022-5bda6cd99743/)\n## [How to Build a Machine Learning Demo in 2022](https://towardsdatascience.com/how-to-build-a-machine-learning-demo-in-2022-5bda6cd99743/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nLearn why you should build demos for your Machine Learning models in 2022\n[Nicolas Jaccard](https://towardsdatascience.com/author/nicjac/)\nJanuary 18, 202212 min read\n  * [![](../images/006.jpg)](https://towardsdatascience.com/how-to-find-the-best-multilingual-embedding-model-for-your-rag-40325c308ebb/)\n## [How to Find the Best Multilingual Embedding Model for Your RAG](https://towardsdatascience.com/how-to-find-the-best-multilingual-embedding-model-for-your-rag-40325c308ebb/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nOptimize the Embedding Space for Improving RAG\n[Iulia Brezeanu](https://towardsdatascience.com/author/brezeanu.iulia/)\nJanuary 27, 20248 min read\n  * [![](../images/007.jpg)](https://towardsdatascience.com/introduction-to-pandas-cc3bc6355155/)\n## [Introduction to Pandas](https://towardsdatascience.com/introduction-to-pandas-cc3bc6355155/)\n[Programming](https://towardsdatascience.com/category/programming/)\nEnhance your Data Science skills in Python with the Pandas API.\n[Dan Root](https://towardsdatascience.com/author/third_eye_cyborg/)\nOctober 30, 20201 min read\n  * [![](../images/008.png)](https://towardsdatascience.com/monitoring-nlp-models-in-production-ac65745772cf/)\n## [Monitoring NLP models in production](https://towardsdatascience.com/monitoring-nlp-models-in-production-ac65745772cf/)\n[NLP](https://towardsdatascience.com/category/artificial-intelligence/nlp/)\nA code tutorial on detecting drift in text data\n[Elena Samuylova](https://towardsdatascience.com/author/elena.samuylova/)\nFebruary 20, 202313 min read\n  * [![](../images/009.jpeg)](https://towardsdatascience.com/explainable-artificial-intelligence-part-2-model-interpretation-strategies-75d4afa6b739/)\n## [Model Interpretation Strategies](https://towardsdatascience.com/explainable-artificial-intelligence-part-2-model-interpretation-strategies-75d4afa6b739/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nLearn about model interpretation techniques, limitations and advances\n[Dipanjan (DJ) Sarkar](https://towardsdatascience.com/author/djsarkar/)\nOctober 31, 201821 min read\n  * [![](../images/010.jpeg)](https://towardsdatascience.com/serving-tensorrt-models-with-nvidia-triton-inference-server-5b68cc141d19/)\n## [Serving TensorRT Models with NVIDIA Triton Inference Server](https://towardsdatascience.com/serving-tensorrt-models-with-nvidia-triton-inference-server-5b68cc141d19/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAchieving optimal throughput and latency with model inference on high client-server traffic\n[Tan Pengshi Alvin](https://towardsdatascience.com/author/tanpengshi/)\nDecember 15, 20226 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 3): RFM Analysis for Customer Segmentation in Pandas | Towards Data Science",
    "description": "How to build, score, and interpret RFM segments step by step",
    "keywords": null,
    "author": "Ibrahim Salami",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "EDA in Public (Part 3): RFM Analysis for Customer Segmentation in Pandas",
    "og:description": "How to build, score, and interpret RFM segments step by step",
    "og:url": "https://towardsdatascience.com/eda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-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": "12 min read",
    "article:published_time": "2026-01-01T10:00:09.000Z",
    "article:modified_time": "2026-01-01T10:00:09.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": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_000.txt",
      "chars": 63
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_001.txt",
      "chars": 138
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_002.txt",
      "chars": 114
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_003.txt",
      "chars": 18
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_004.txt",
      "chars": 263
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_005.txt",
      "chars": 262
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_006.txt",
      "chars": 47
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_007.txt",
      "chars": 20
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_008.txt",
      "chars": 108
    },
    {
      "language": "txt",
      "file": "attachments/fc5bdb5647f7/code/block_009.txt",
      "chars": 325
    }
  ],
  "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-20T18:07:10Z"
    },
    {
      "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-20T18:07:10Z"
    },
    {
      "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-20T18:07:10Z"
    },
    {
      "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-20T18:07:10Z"
    }
  ],
  "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/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/ibrahim.salami/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/"
    },
    {
      "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/deep-dives/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/exploratory-data-analysis/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/pandas/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/instacart-users-segmentation-and-market-basket-analysis-d88378f75f73/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/yz6378/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/introduction-to-applied-linear-algebra-vectors-29ff7e0539/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "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/ai-data-scientist"
    },
    {
      "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+3%29%3A+RFM+Analysis+for+Customer+Segmentation+in%C2%A0Pandas&u=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=EDA+in+Public+%28Part+3%29%3A+RFM+Analysis+for+Customer+Segmentation+in%C2%A0Pandas&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=EDA+in+Public+%28Part+3%29%3A+RFM+Analysis+for+Customer+Segmentation+in%C2%A0Pandas&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-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:32:37Z",
  "source_url": "https://towardsdatascience.com/eda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-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[Data Science](https://towardsdatascience.com/category/data-science/)\n# EDA in Public (Part 3): RFM Analysis for Customer Segmentation in Pandas\nHow to build, score, and interpret RFM segments step by step\n[Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\nJanuary 1, 202612 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\nWelcome back! If you’ve been following along, we’ve come a long way. In [**Part 1**](https://towardsdatascience.com/eda-in-public-part-1-cleaning-exploring-sales-data-with-pandas/), we did the “dirty work” of cleaning and prepping.\nIn [**Part 2**](https://towardsdatascience.com/eda-in-public-part-2-product-deep-dive-time-series-analysis-in-pandas/), we zoomed out to a high-altitude view of NovaShop’s world — spotting the big storms (high-revenue countries) and the seasonal patterns (the massive Q4 rush).\nBut here’s the thing: a business doesn’t actually sell to “months” or “countries.” It sells to **human beings**.\nIf you treat every customer exactly the same, you’re making two very expensive mistakes:\n  * **Over-discounting:** Giving a “20% off” coupon to someone who was already reaching for their wallet.\n  * **Ignoring the “Quiet” Ones:** Failing to notice when a formerly loyal customer stops visiting, until they’ve been gone for six months and it’s too late to win them back.\n\n\n**The Solution? Behavioural Segmentation.**\nInstead of guessing, we’re going to use the data to let the customers tell us who they are. We do this using the gold standard of retail analytics: **RFM Analysis**.\n  * **Recency (R):** How recently did they buy? (Are they still engaged with us?)\n  * **Frequency (F):** How often do they buy? (Are they loyal, or was it a one-off?)\n  * **Monetary (M):** How much do they spend? (What is their total business impact?)\n\n\nBy the end of this part, we’ll move beyond “Top 10 Products” and actually assign a specific, actionable **Label** to every single customer in NovaShop’s database.\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist) roadmap.\n## Data Preparation: The “Missing ID” Pivot\nBefore we can start scoring, we have to address a decision we made back in Part 1.\nIf you remember our **Initial Inspection** , we noticed that about 25% of our rows were missing a `CustomerID`. At the time, we made a strategic business decision to _keep those rows. We needed them to calculate the_ accurate total revenue and see which products were popular overall.\nFor RFM analysis, the rules change. You cannot track behavior without a consistent identity. We can’t know how “frequent” a customer is if we don’t know who they are!\nSo, our first step in Part 3 is to isolate our “Trackable Universe” by filtering for rows where a `CustomerID` exists.\n## Engineering the RFM Metrics\nNow that we have a dataset where every row is linked to a specific person, we need to aggregate all their individual transactions into three summary numbers: Recency, Frequency, and Monetary.\n### Defining the Snapshot Date\nBefore calculating RFM, we need a **reference point in time** , commonly called the _snapshot date_.\nHere, we take the most recent transaction date in the dataset and add one day. This snapshot date represents the moment at which we’re evaluating customer behaviour.\npython\n\n```\nsnapshot_date = df['InvoiceDate'].max() + dt.timedelta(days=1)\n```\n\nWe added one day, so customers who bought on the most recent date still have a Recency value of 1 day, not 0. This keeps the metric intuitive and avoids edge-case problems.\n### Aggregating Transactions at the Customer Level\npython\n\n```\nrfm = df.groupby(‘CustomerID’).agg({\n‘InvoiceDate’: lambda x: (snapshot_date — x.max()).days,\n‘InvoiceNo’: ‘nunique’,\n‘Revenue’: ‘sum’\n})\n```\n\nEach row in our dataset represents a single transaction. To calculate RFM, we need to **collapse these transactions into one row per customer**.\nWe do this by grouping the data by `CustomerID` and applying different aggregation functions:\n  * **Recency** : For each customer, we find their most recent purchase date and calculate how many days have passed since then.\n  * **Frequency:** We count the number of unique invoices associated with each customer. This tells us how often they’ve made purchases.\n  * **Monetary** : We sum the total revenue generated by each customer across all transactions.\n\n\n### Renaming Columns for Clarity\npython\n\n```\nrfm.rename(columns={\n'InvoiceDate': 'Recency',\n'InvoiceNo': 'Frequency',\n'Revenue': 'Monetary'\n}, inplace=True)py\n```\n\nThe aggregation step keeps the original column names, which can be confusing. Renaming them makes the dataframe immediately readable and aligns it with standard RFM terminology.\nNow each column clearly answers a business question:\n  * **Recency** → How recently did the customer purchase?\n  * **Frequency** → How often do they purchase?\n  * **Monetary** → How much revenue do they generate?\n\n\n## Inspecting the Result\npython\n\n```\nprint(rfm.head())\n```\n\nThe final `rfm` dataframe contains **one row per customer** , with three intuitive metrics summarizing their behavior. \n**Output:**\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/12/rfm-analysis-0.jpg)\nLet’s walk through this the way we would with NovaShop in a real conversation.\n> “When was the last time this customer bought from us?”\nThat’s exactly what **Recency** answers.\nTake **Customer 12347** :\n  * Recency = **2**\n  * Translation: _“This customer bought something just two days ago.”_\n\n\nThey’re fresh. They remember the brand. They’re still engaged.\nNow compare that to **Customer 12346** :\n  * Recency = **326**\n  * Translation: _“They haven’t bought anything in almost a year.”_\n\n\nEven though this customer spent a lot in the past, they’re currently silent.\n**From NovaShop’s perspective:** Recency tells us who’s still listening and who might need a nudge (or a wake-up call).\n> “Is this a one-time buyer or someone who keeps coming back?”\nThat’s where **Frequency** comes in.\nLook again at **Customer 12347** :\n  * Frequency = **7**\n  * They didn’t just buy once — they came back again and again.\n\n\nNow look at several others:\n  * Frequency = **1**\n  * One purchase, then gone.\n\n\n**From a business perspective,** frequency separates casual shoppers from loyal customers.\n> “Who actually brings in the money?”\nThat’s the **Monetary** column.  \nAnd this is where things get interesting.\n**Customer 12346** :\n  * Monetary = **£77,183.60**\n  * Frequency = **1**\n  * Recency = **326**\n\n\nThis tells a very specific story:\nA single, very large order… a long time ago… and nothing since.\nNow compare that to **Customer 12347** :\n  * Lower total spend\n  * Multiple purchases\n  * Very recent activity\n\n\n**Important insight for NovaShop:** A “high-value” customer in the past isn’t necessarily a valuable customer _today_.\n### Why This View Changes the Conversation\nIf NovaShop only looked at total revenue, they might focus all their attention on customers like **12346**.\nBut RFM shows us that:\n  * Some customers spent a lot once and disappeared\n  * Some spend less but stay loyal\n  * Some are active _right now_ and ready to be engaged\n\n\nThis output helps NovaShop stop guessing and start prioritizing:\n  * Who should get retention emails?\n  * Who needs reactivation campaigns?\n  * Who is already loyal and should be rewarded?\n\n\nRight now, these are still raw numbers.\nIn the next step, we’ll **rank and score** these customers, so NovaShop doesn’t have to interpret rows manually. Instead, they’ll see clear segments like:\n  * _Champions_\n  * _Loyal Customers_\n  * _At-Risk_\n  * _Lost_\n\n\nThat’s where this becomes a real decision-making tool — not just a dataframe.\n## Turning RFM Numbers Into Meaningful Customer Segments\nAt this stage, NovaShop has a table full of numbers. Useful — but not exactly decision-friendly.\nA marketing team can’t realistically scan hundreds or thousands of rows asking:\n  * _Is a Recency of 19 good or bad?_\n  * _Is Frequency = 2 impressive?_\n  * _How much Monetary value is “high”?_\n\n\nOur goal is to rank customers relative to one another and turn raw values into scores _._\n### Step 1: Ranking Customers by Each RFM Metric\nInstead of treating Recency, Frequency, and Monetary as absolute values, we look at where each customer **stands compared to everyone else**.\n  * Customers with **more recent purchases** should score higher\n  * Customers who **buy more often** should score higher\n  * Customers who **spend more** should score higher\n\n\nIn practice, we do this by splitting each metric into **quantiles** (usually 4 or 5 buckets).\nHowever, there’s a small real-world wrinkle. This is something I came across while working on this project\nIn transactional datasets, it’s common to see:\n  * Many customers with the same Frequency (e.g. one-time buyers)\n  * Highly skewed Monetary values\n  * Small samples where quantile binning can fail\n\n\nTo keep things robust and readable, we’ll wrap the scoring logic in a small helper function.\npython\n\n```\ndef rfm_score(series, ascending=True, n_bins=5):\n# Rank the values to ensure uniqueness\nranked = series.rank(method=’first’, ascending=ascending)\n\n# Use pd.qcut on the ranks to assign bins\nreturn pd.qcut(\nranked,\nq=n_bins,\nlabels=range(1, n_bins+1)\n).astype(int)\n```\n\nTo explain what’s going on here:\n  * We’re creating a helper function that turns a raw numeric column into a clean **RFM score** using quantile-based binning.\n  * First, the values are ranked.So, instead of binning the raw values directly, we rank them first. This step guarantees **unique ordering** , even when many customers share the same value (a common issue in RFM data). \n  * The `ascending` flag lets us flip the logic depending on the metric — for example, lower recency is better, while higher frequency and monetary values are better.\n  * Next, we’re applying **quantile-based binning.**`qcut` splits the ranked values into `n_bins` equally sized groups. Each customer is assigned a score from **1 to 5** (by default), where the score represents their relative position within the distribution.\n  * Finally, the results will be converted to integers for easy use in analysis and segmentation.\n\n\nIn short, this function provides a **robust and reusable way** to score RFM metrics without running into duplicate bin edge errors — and without overcomplicating the logic.\n### Step 2: Applying the Scores\nNow we can score each metric cleanly and consistently:\npython\n\n```\n# Assign R, F, M scores\nrfm['R_Score'] = rfm_score(rfm['Recency'], ascending=False) # Recent purchases = high score\nrfm['F_Score'] = rfm_score(rfm['Frequency']) # More frequent = high score\nrfm['M_Score'] = rfm_score(rfm['Monetary']) # Higher spend = high score\n```\n\nThe only special case here is **Recency** :\n  * Lower values mean more recent activity\n  * So we reverse the ranking with `ascending=False`\n  * Everything else follows the natural “higher is better” rule.\n\n\n#### What This Means for NovaShop\nInstead of seeing this:\nmarkup\n\n```\nRecency = 326Frequency = 1Monetary = 77,183.60\n```\n\nNovaShop now sees something like:\nmarkup\n\n```\nR = 1, F = 1, M = 5\n```\n\nThat’s instantly more interpretable:\n  * Not recent\n  * Not frequent\n  * High spender (historically)\n\n\n### Step 3: Creating a Combined RFM Score\nNow we combine these three scores into a single RFM code:\npython\n\n```\nrfm['RFM_Score'] = (\nrfm['R_Score'].astype(str) +\nrfm['F_Score'].astype(str) +\nrfm['M_Score'].astype(str)\n)\n```\n\nThis produces values like:\n  * **555** → Best customers\n  * **155** → High spenders who haven’t returned\n  * **111** → Customers who are likely gone\n\n\nEach customer now carries a compact behavioral fingerprint. And we’re not done yet.\n## Translating RFM Scores Into Customer Segments\nRaw scores are nice, but let’s be honest: **no marketing manager wants to look at 555, 154, or 311 all day**.\nNovaShop needs **labels that make sense at a glance**. That’s where RFM segments come in.\n### Step 1: Defining Segments\nUsing RFM scores, we can classify customers into meaningful categories. Here’s a common approach:\n  * **Champions:** Top Recency, top Frequency, top Monetary (555) — your best customers\n  * **Loyal Customers:** Regular buyers, may not be spending the most, but keep coming back\n  * **Big Spenders:** High Monetary, but not necessarily recent or frequent\n  * **At-Risk:** Used to buy, but haven’t returned recently\n  * **Lost:** Low scores in all three metrics — likely disengaged\n  * **Promising / New:** Recent customers with lower frequency or monetary spend\n\n\nThis transforms **abstract numbers** into a **narrative** that marketing and management can act on.\n### Step 2: Mapping Scores to Segments\nHere’s an example using simple conditional logic:\npython\n\n```\ndef rfm_segment(row):\nif row['R_Score'] >= 4 and row['F_Score'] >= 4 and row['M_Score'] >= 4:\nreturn 'Champions'\nelif row['F_Score'] >= 4:\nreturn 'Loyal Customers'\nelif row['M_Score'] >= 4:\nreturn 'Big Spenders'\nelif row['R_Score'] <= 2:\nreturn 'At-Risk'\nelse:\nreturn 'Others'\nrfm['Segment'] = rfm.apply(rfm_segment, axis=1)\n```\n\nNow each customer has a **human-readable label** , making it immediately actionable.\nLet’s review our results using `rfm.head()`  \n\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/12/rfm-analysis.jpg)\n### Step 3: Turning Segments into Strategy\nWith labeled segments, NovaShop can:\n  * **Reward Champions** → Exclusive deals, loyalty points\n  * **Re-engage Big Spenders & At-Risk customers** → Personalized emails or discounts\n  * **Focus marketing wisely** → Don’t waste effort on customers who are truly lost\n\n\nThis is the moment where data becomes strategy.\n## What NovaShop Should Do Next (Key Takeaways & Recommendations)\nAt the start of this analysis, NovaShop had a familiar problem:  \n**A lot of transactional data, but limited clarity on customer behaviour**.\nBy applying the RFM framework, we’ve turned raw purchase history into a clear, structured view of who NovaShop’s customers are — and how they behave.\nNow let’s talk about what to actually do with it.\n### 1. Protect and Reward Your Best Customers\n**Champions** and **Loyal Customers** are already doing what every business wants:\n  * They buy recently\n  * They buy often\n  * They generate consistent revenue\n\n\nThese customers don’t need heavy discounts — they need recognition.\n**Recommended actions:**\n  * Early access to sales\n  * Loyalty points or VIP tiers\n  * Personalized thank-you emails\n\n\n> _The goal here isn’t acquisition, it’s retention._\n### 2. Re-Engage High-Value Customers Before They’re Lost\nThe most dangerous segment for NovaShop isn’t “Lost” customers.  \nIt’s **At-Risk** and **Big Spenders**.\nThese customers:\n  * Have shown clear value in the past\n  * But haven’t purchased recently\n  * Are one step away from churning completely\n\n\n**Recommended actions:**\n  * Targeted win-back campaigns\n  * Personalized offers (not blanket discounts)\n  * Reminder emails tied to past purchase behavior\n\n\n> _Winning back an existing customer is almost always cheaper than acquiring a new one._\n### 3. Don’t Over-Invest in Truly Lost Customers\nSome customers will inevitably churn. RFM helps NovaShop identify those customers early and avoid spending ad budget, discounts and marketing effort on users who are unlikely to return. This isn’t about being cold — it’s about being **efficient**.\n### 4. Use RFM as a Living Framework, Not a One-Off Analysis\nThe real power of RFM comes when it’s:\n  * Recomputed monthly or quarterly\n  * Integrated into dashboards\n  * Used to track movement between segments over time\n\n\nFor NovaShop, this means asking questions like:\n  * _How many At-Risk customers became Loyal this month?_\n  * _Are Champions increasing or shrinking?_\n  * _Which campaigns actually move customers up the ladder?_\n\n\nRFM turns customer behaviour into something **measurable and trackable**.\n## Final Thoughts: Closing the EDA in Public Series\nWhen I started this _EDA in Public_ series, I wasn’t trying to build the perfect analysis or demonstrate advanced techniques. I wanted to slow down and share how I actually think when working with real data. Not the polished version, but the messy, iterative process that usually stays hidden.\nThis project began with a noisy CSV and a lot of open questions. Along the way, there were small issues that only surfaced once I paid closer attention — dates stored as strings, assumptions that didn’t quite hold up, metrics that needed context before they made sense. Working through those moments in public was uncomfortable at times, but also genuinely valuable. Each correction made the analysis stronger and more honest.\nOne thing this process reinforced for me is that most meaningful insights don’t come from complexity. They come from slowing down, structuring the data properly, and asking better questions. By the time I reached the RFM analysis, the value wasn’t in the formulas themselves — it was in what they forced me to confront. A customer who spent a lot once isn’t necessarily valuable today. Recency matters. Frequency matters. And none of these metrics mean much in isolation.\nEnding the series with RFM felt deliberate. It sits at the point where technical work meets business thinking, where tables turn into conversations and numbers turn into decisions. It’s also where exploratory analysis stops being purely descriptive and starts becoming practical. At that stage, the goal is no longer just to understand the data, but to decide what to do next.\nDoing this work in public changed how I approach analysis. Writing things out forced me to explain my reasoning, question my assumptions, and be comfortable showing imperfect work. It reminded me that EDA isn’t a checklist you rush through — it’s a dialogue with the data. Sharing that dialogue makes you more thoughtful and more accountable.\nThis may be the final part of the _EDA in Public_ series, but it doesn’t feel like an endpoint. Everything here could evolve into dashboards, automated pipelines, or deeper customer analysis. \nAnd if you’re a founder, analyst, or team working with customer or sales data and trying to make sense of it, this kind of exploratory work is often where the biggest clarity comes from. These are exactly the kinds of problems I enjoy working through — slowly, thoughtfully, and with the business context in mind.\nIf you’re documenting your own analyses, I’d love to see how you approach it. And if you’re wrestling with similar questions in your data and want to talk through them, feel free to reach out on any of the platforms below. Good data conversations usually start there.\nThanks for following along!\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## 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[Deep Dives](https://towardsdatascience.com/tag/deep-dives/)[Exploratory Data Analysis](https://towardsdatascience.com/tag/exploratory-data-analysis/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Pandas](https://towardsdatascience.com/tag/pandas/)[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-3-rfm-analysis-for-customer-segmentation-in-pandas%2F&title=EDA%20in%20Public%20\\(Part%203\\)%3A%20RFM%20Analysis%20for%20Customer%20Segmentation%20in%C2%A0Pandas)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas%2F&title=EDA%20in%20Public%20\\(Part%203\\)%3A%20RFM%20Analysis%20for%20Customer%20Segmentation%20in%C2%A0Pandas)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Feda-in-public-part-3-rfm-analysis-for-customer-segmentation-in-pandas%2F&text=EDA%20in%20Public%20\\(Part%203\\)%3A%20RFM%20Analysis%20for%20Customer%20Segmentation%20in%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/2020/10/0mh45Ds5hgkr5rKBK.png)](https://towardsdatascience.com/instacart-users-segmentation-and-market-basket-analysis-d88378f75f73/)\n## [Instacart Users Segmentation and Market Basket Analysis](https://towardsdatascience.com/instacart-users-segmentation-and-market-basket-analysis-d88378f75f73/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nXin Yu, Yingyuan (Valerie) Zhang, Yutong (Grace) Zhu\n[Yingyuan (Valerie) Zhang](https://towardsdatascience.com/author/yz6378/)\nOctober 12, 20205 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/11/1jdtcAfQA7rb03dsy5dS5Fw-scaled.jpeg)](https://towardsdatascience.com/introduction-to-applied-linear-algebra-vectors-29ff7e0539/)\n## [Introduction to Applied Linear Algebra: Vectors](https://towardsdatascience.com/introduction-to-applied-linear-algebra-vectors-29ff7e0539/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nThis article gives an introduction to vectors, vector operations and their application in the field of data science.\n[Deniz Tuzsus](https://towardsdatascience.com/author/deniz.tuzsus/)\nNovember 25, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/1oAgFgTZcGRhcxDT-74m9hQ-scaled.jpeg)](https://towardsdatascience.com/creating-a-machine-learning-model-with-sql-81d843a5307c/)\n## [Creating a Machine Learning Model with SQL](https://towardsdatascience.com/creating-a-machine-learning-model-with-sql-81d843a5307c/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBuild an ML model using SQL on Google Big Query\n[Anuj Syal](https://towardsdatascience.com/author/syal-anuj/)\nNovember 12, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/01/0YqYC_HRD6JB8EZwB-scaled.jpg)](https://towardsdatascience.com/how-to-build-a-machine-learning-demo-in-2022-5bda6cd99743/)\n## [How to Build a Machine Learning Demo in 2022](https://towardsdatascience.com/how-to-build-a-machine-learning-demo-in-2022-5bda6cd99743/)\n[Deep Learning](https://towardsdatascience.com/category/artificial-intelligence/deep-learning/)\nLearn why you should build demos for your Machine Learning models in 2022\n[Nicolas Jaccard](https://towardsdatascience.com/author/nicjac/)\nJanuary 18, 202212 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2024/01/0Ln4p2tHZSghTlKH7.jpg)](https://towardsdatascience.com/how-to-find-the-best-multilingual-embedding-model-for-your-rag-40325c308ebb/)\n## [How to Find the Best Multilingual Embedding Model for Your RAG](https://towardsdatascience.com/how-to-find-the-best-multilingual-embedding-model-for-your-rag-40325c308ebb/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nOptimize the Embedding Space for Improving RAG\n[Iulia Brezeanu](https://towardsdatascience.com/author/brezeanu.iulia/)\nJanuary 27, 20248 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/10/08rOPOLq48c0JkWkF-scaled.jpg)](https://towardsdatascience.com/introduction-to-pandas-cc3bc6355155/)\n## [Introduction to Pandas](https://towardsdatascience.com/introduction-to-pandas-cc3bc6355155/)\n[Programming](https://towardsdatascience.com/category/programming/)\nEnhance your Data Science skills in Python with the Pandas API.\n[Dan Root](https://towardsdatascience.com/author/third_eye_cyborg/)\nOctober 30, 20201 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/1rOItEmRPx6MFPmZ4joWWKA.png)](https://towardsdatascience.com/monitoring-nlp-models-in-production-ac65745772cf/)\n## [Monitoring NLP models in production](https://towardsdatascience.com/monitoring-nlp-models-in-production-ac65745772cf/)\n[NLP](https://towardsdatascience.com/category/artificial-intelligence/nlp/)\nA code tutorial on detecting drift in text data\n[Elena Samuylova](https://towardsdatascience.com/author/elena.samuylova/)\nFebruary 20, 202313 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2018/10/1kQNRe0h_v5iuG6BczAW2FA.jpeg)](https://towardsdatascience.com/explainable-artificial-intelligence-part-2-model-interpretation-strategies-75d4afa6b739/)\n## [Model Interpretation Strategies](https://towardsdatascience.com/explainable-artificial-intelligence-part-2-model-interpretation-strategies-75d4afa6b739/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nLearn about model interpretation techniques, limitations and advances\n[Dipanjan (DJ) Sarkar](https://towardsdatascience.com/author/djsarkar/)\nOctober 31, 201821 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/12/1MoIds7b83MgSohjKqtCWsQ-scaled.jpeg)](https://towardsdatascience.com/serving-tensorrt-models-with-nvidia-triton-inference-server-5b68cc141d19/)\n## [Serving TensorRT Models with NVIDIA Triton Inference Server](https://towardsdatascience.com/serving-tensorrt-models-with-nvidia-triton-inference-server-5b68cc141d19/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nAchieving optimal throughput and latency with model inference on high client-server traffic\n[Tan Pengshi Alvin](https://towardsdatascience.com/author/tanpengshi/)\nDecember 15, 20226 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/fc5bdb5647f7/pages/",
  "body_markdown_path": "attachments/fc5bdb5647f7/pages/archived-body.md",
  "local_html": "attachments/fc5bdb5647f7/pages/archived-body.html",
  "body_source": "prior_capture"
}