{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Ibrahim Salami",
  "title_listed": "Write Pandas Like a Pro With Method Chaining Pipelines",
  "keywords": "",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "否",
  "url": "https://towardsdatascience.com/this-one-pandas-pattern-separates-beginners-from-intermediate-users/",
  "publish_date": "2026-04-12",
  "corpus_stage": "",
  "notes": "",
  "id": "48c5e48c6d3c",
  "collected_at": "2026-10-02T11:44:34",
  "title": "Write Pandas Like a Pro With Method Chaining Pipelines | Towards Data Science",
  "body_markdown": "![Revisit consent button](../images/body-df29beacd7496220cc94.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](../images/body-2159bb67f3de8ad870eb.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Programming](https://towardsdatascience.com/category/programming/)\n# Write Pandas Like a Pro With Method Chaining Pipelines\nMaster method chaining, assign(), and pipe() to write cleaner, testable, production-ready Pandas code\n[Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\nApril 12, 202614 min read\n![](../images/000.jpg)\nGenerated with Gemini AI\nI opened an old notebook recently and immediately closed it.\nNot because it was wrong. The code worked. The numbers checked out.\nBut I had no idea what was going on.\nThere were variables everywhere. `df1`, `df2`, `final_df`, `final_final`. Each step made sense in isolation, but as a whole it felt like I was tracing a maze. I had to read line by line just to understand what I had already done.\nAnd the funny thing is, this is how most of us start with Pandas.\nYou learn a few operations. You filter here, create a column there, group and aggregate. It gets the job done. But over time, your code starts to feel harder to trust, harder to revisit, and definitely harder to share.\nThat was the point I realized something.\nThe gap between beginner and intermediate Pandas users is not about knowing more functions. It is about how you structure your transformations.\nThere is a pattern that quietly changes everything once you see it. Your code becomes easier to read. Easier to debug. Easier to build on.\nIt is called method chaining.\nIn this article, I will walk through how I started using method chaining properly, along with `assign()` and `pipe()`, and how it changed the way I write Pandas code. If you have ever felt like your notebooks are getting messy as they grow, this will probably click for you.\nLearn this step by step with the interactive [Computer Science](https://roadmap.sh/computer-science) roadmap.\n## The Shift: What Intermediate Pandas Users Do Differently\nAt first, I thought getting better at Pandas meant learning more functions.\nMore tricks. More syntax. More ways to manipulate data.\nBut the more I built, the more I noticed something. The people who were actually good at Pandas were not necessarily using more functions than I was. Their code just looked… different.\nCleaner. More intentional. Easier to follow.\nInstead of writing step by step code with lots of intermediate variables, they wrote transformations that flowed into each other. You could read their code from top to bottom and understand exactly what was happening to the data at each stage.\nIt almost felt like reading a story.\nThat is when it clicked for me. The real upgrade is not about _what_ you use. It is about _how_ you structure it.\nInstead of thinking:\n> “What do I do next to this DataFrame?”\nYou start thinking:\n> “What transformation comes next?”\nThat small shift changes everything.\nAnd this is where method chaining comes in.\nMethod chaining is not just a cleaner way to write Pandas. It is a different way to think about working with data. Each step takes your DataFrame, transforms it, and passes it along. No unnecessary variables. No jumping around.\nJust a clear, readable flow from raw data to final result.\nIn the next section, I will show you exactly what this looks like using a real example.\n## The “Before”: How Most of Us Write Pandas\nTo make this concrete, let’s say we want to answer a simple question:\n> Which product categories are generating the most revenue each month?\nI pulled a small sales dataset with order details, product categories, prices, and dates. Nothing fancy.\npython\n\n```\nimport pandas as pd\ndf = pd.read_csv(\"sales.csv\")\nprint(df.head())\n```\n\nOutput\ntext\n\n```\norder_id customer_id     product     category  quantity  price  order_date\n0      1001        C001      Laptop  Electronics         1   1200  2023-01-05\n1      1002        C002  Headphones  Electronics         2    150  2023-01-07\n2      1003        C003    Sneakers      Fashion         1     80  2023-01-10\n3      1004        C001     T-Shirt      Fashion         3     25  2023-01-12\n4      1005        C004     Blender         Home         1     60  2023-01-15\n```\n\nNow, here is how I would have written this not too long ago:\npython\n\n```\n# Create a new column for revenue\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\n\n# Filter for orders from 2023 onwards\ndf_filtered = df[df[\"order_date\"] >= \"2023-01-01\"]\n\n# Convert order_date to datetime and extract month\ndf_filtered[\"month\"] = pd.to_datetime(df_filtered[\"order_date\"]).dt.to_period(\"M\")\n\n# Group by category and month, then sum revenue\ngrouped = df_filtered.groupby([\"category\", \"month\"])[\"revenue\"].sum()\n\n# Convert Series back to DataFrame\nresult = grouped.reset_index()\n\n# Sort by revenue descending\nresult = result.sort_values(by=\"revenue\", ascending=False)\nprint(result)\n```\n\nThis works. You get your answer.\ntext\n\n```\n  category    month  revenue\n1  Electronics  2023-02     2050\n2  Electronics  2023-03     1590\n0  Electronics  2023-01     1500\n8         Home  2023-03      225\n6         Home  2023-01      210\n5      Fashion  2023-03      205\n7         Home  2023-02      180\n4      Fashion  2023-02      165\n3      Fashion  2023-01      155\n```\n\nBut there are a few problems that start to show up as your analysis grows.\nFirst, the flow is hard to follow. You have to keep track of `df`, `df_filtered`, `grouped`, and `result`. Each variable represents a slightly different state of the data.\nSecond, the logic is scattered. The transformation is happening step by step, but not in a way that feels connected. You are mentally stitching things together as you read.\nThird, it is harder to reuse or test. If you want to tweak one part of the logic, you now have to trace where everything is being modified.  \nThis is the kind of code that works fine today… but becomes painful when you come back to it a week later.\nNow compare that to how the same logic looks when you start thinking in transformations instead of steps.\n## The “After”: When Everything Clicks\nNow let’s solve the exact same problem again.\nSame dataset. Same goal.\n> Which product categories are generating the most revenue each month?\nHere’s what it looks like when you start thinking in transformations:\npython\n\n```\nresult = (\npd.read_csv(\"sales.csv\") # Start with raw data\n.assign(\n# Create revenue column\nrevenue=lambda df: df[\"quantity\"] * df[\"price\"],\n\n# Convert order_date to datetime\norder_date=lambda df: pd.to_datetime(df[\"order_date\"]),\n\n# Extract month from order_date\nmonth=lambda df: df[\"order_date\"].dt.to_period(\"M\")\n)\n# Filter for orders from 2023 onwards\n.loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n\n# Group by category and month, then sum revenue\n.groupby([\"category\", \"month\"], as_index=False)[\"revenue\"]\n.sum()\n\n# Sort by revenue descending\n.sort_values(by=\"revenue\", ascending=False)\n)\nprint(result)\n```\n\nSame output. Completely different feel.\ntext\n\n```\n category    month  revenue\n1  Electronics  2023-02     2050\n2  Electronics  2023-03     1590\n0  Electronics  2023-01     1500\n8         Home  2023-03      225\n6         Home  2023-01      210\n5      Fashion  2023-03      205\n7         Home  2023-02      180\n4      Fashion  2023-02      165\n3      Fashion  2023-01      155\n```\n\nThe first thing you notice is that everything flows. There is no jumping between variables or trying to remember what `df_filtered` or `grouped` meant.\nEach step builds on the last one.\nYou start with the raw data, then:\n  * create revenue\n  * convert dates\n  * extract the month\n  * filter\n  * group\n  * aggregate\n  * sort\n\n\nAll in one continuous pipeline.\nYou can read it top to bottom and understand exactly what is happening to the data at each stage.\nThat is the part that surprised me the most.\nIt is not just shorter code. It is _clearer code_.\nAnd once you get used to this, going back to the old way feels… uncomfortable.\nThere are a couple of things happening here that make this work so well.\nWe are not just chaining methods. We are using a few specific tools that make chaining actually practical.\nIn the next section, let’s break those down.\n## Breaking Down the Pattern\nWhen I first saw this style of Pandas code, it looked a bit intimidating.\nEverything was chained together. No intermediate variables. A lot happening in a small space.\nBut once I slowed down and broke it into pieces, it started to make sense.\nThere are really just three ideas carrying everything here:\n  * method chaining\n  * `assign()`\n  * `pipe()`\n\n\nLet’s go through them one by one.  \n\n### Method Chaining (The Foundation)\nAt its core, method chaining is simple. Each step takes a DataFrame, applies a transformation, and returns a new DataFrame. That new DataFrame is immediately passed into the next step.\nSo instead of this:\npython\n\n```\ndf = step1(df) \n\ndf = step2(df) \n\ndf = step3(df)\n```\n\nYou do this:\npython\n\n```\ndf = step1(df).step2().step3()\n```\n\nThat is literally it.\nBut the impact is bigger than it looks.\nIt forces you to think in terms of _flow_. Each line becomes one transformation. You are no longer jumping around or storing temporary states. You are just moving forward.\nThat is why the code starts to feel more readable. You can follow the transformation from start to finish without holding multiple versions of the data in your head.  \n\n###  `assign()` — Keeping Everything in the Flow\nThis is the one that really unlocked chaining for me.\nBefore this, anytime I wanted to create a new column, I would break the flow:\npython\n\n```\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\n```\n\nThat works, but it interrupts the pipeline.\n`assign()` lets you do the same thing without breaking the chain:\npython\n\n```\n.assign(revenue=lambda df: df[\"quantity\"] * df[\"price\"])\n```\n\nAt first, the `lambda df:` part felt weird.\nBut the idea is simple. You are saying:\n“Take the current DataFrame, and use it to define this new column.”\nThe key benefit is that everything stays in one place. You can see where the column is created and how it is used, all within the same flow.\nIt also encourages a cleaner style where transformations are grouped logically instead of scattered across the notebook.  \n\n###  `pipe()` — Where Things Start to Feel Powerful\n`pipe()` is the one I ignored at first.\nI thought, “I can already chain methods, why do I need this?”  \nThen I ran into a problem.\nSome transformations are just too complex to fit neatly into a chain.\nYou either:  \nwrite messy inline logic  \nor break the chain completely\nThat is where `pipe()` comes in.\nIt allows you to pass your DataFrame into a custom function without breaking the flow.\nFor example:\npython\n\n```\ndef filter_high_value_orders(df):\n    return df[df[\"revenue\"] > 500]\n\ndf = (\n    pd.read_csv(\"sales.csv\")\n    .assign(revenue=lambda df: df[\"quantity\"] * df[\"price\"])\n    .pipe(filter_high_value_orders)\n)\n```\n\nNow your logic is cleaner, reusable and easier to test\nThis is the point where things started to feel different for me.\nInstead of writing long scripts, I was starting to build small, reusable transformation steps.\nAnd that is when it clicked.\nThis is not just about writing cleaner Pandas code. It is about writing code that scales as your analysis gets more complex.  \n  \nIn the next section, I want to show how this changes the way you think about working with data entirely.\n## Thinking in Pipelines (The Real Upgrade)\nUp until this point, it might feel like we just made the code look nicer.\nBut something deeper is happening here.\nWhen you start using method chaining consistently, the way you think about working with data begins to change.\nBefore, my approach was very step-by-step.\nI would look at a DataFrame and think:\n> “What do I do next?”\n  * Filter it.\n  * Modify it.\n  * Store it.\n  * Move on.\n\n\nEach step felt a bit disconnected from the last.\nBut with method chaining, that question changes.\nNow it becomes:\n> “What transformation comes next?”\nThat shift is small, but it changes how you structure everything.\nYou stop thinking in terms of isolated steps and start thinking in terms of a flow. A pipeline. Data comes in, gets transformed stage by stage, and produces an output.\nAnd the code reflects that.\nEach line is not just doing something. It is part of a sequence. A clear progression from raw data to insight.\nThis also makes your code easier to reason about.\nIf something breaks, you do not have to scan the entire notebook. You can look at the pipeline and ask:\n  * which transformation might be wrong?\n  * where did the data change in an unexpected way?\n\n\nIt becomes easier to debug because the logic is linear and visible.\nAnother thing I noticed is that it naturally pushes you toward better habits.\n  * You start writing smaller transformations.\n  * You start naming things more clearly.\n  * You start thinking about reuse without even trying.\n\n\nAnd that is where it starts to feel less like “just Pandas” and more like building actual data workflows.\nAt this point, you are not just analyzing data.\nYou are designing how data flows.  \n\n## Real-World Refactor: From Messy to Clean\nLet me show you how this actually plays out.\nInstead of jumping straight from messy code to a perfect chain, I want to walk through how I would refactor this step by step. This is usually how it happens in real life anyway.  \n\n### Step 1: The Starting Point (Messy but Works)\npython\n\n```\ndf = pd.read_csv(\"sales.csv\")  # Load dataset\n\n# Create revenue column\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\n\n# Filter orders from 2023 onwards\ndf_filtered = df[df[\"order_date\"] >= \"2023-01-01\"]\n\n# Convert order_date and extract month\ndf_filtered[\"month\"] = pd.to_datetime(df_filtered[\"order_date\"]).dt.to_period(\"M\")\n\n# Group by category and month, then sum revenue\ngrouped = df_filtered.groupby([\"category\", \"month\"])[\"revenue\"].sum()\n\n# Convert to DataFrame\nresult = grouped.reset_index()\n\n# Sort results\nresult = result.sort_values(by=\"revenue\", ascending=False)\n```\n\nNothing wrong here. This is how most of us start.\nBut we can already see:\n  * too many intermediate variables\n  * transformations are scattered\n  * harder to follow as it grows\n\n\n### Step 2: Reduce Unnecessary Variables\nFirst, remove variables that are not really needed.\npython\n\n```\ndf = pd.read_csv(\"sales.csv\")  # Load dataset\n\n# Create new columns upfront\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\ndf[\"month\"] = pd.to_datetime(df[\"order_date\"]).dt.to_period(\"M\")\n\nresult = (\n    # Filter relevant rows\n    df[df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Aggregate revenue by category and month\n    .groupby([\"category\", \"month\"])[\"revenue\"]\n    .sum()\n    \n    # Convert to DataFrame\n    .reset_index()\n    \n    # Sort results\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\n  \nAlready better. There are fewer moving parts, and some flow is starting to appear  \n\n### Step 3: Introduce Basic Chaining\nNow we start chaining more deliberately.\npython\n\n```\nresult = (\n    pd.read_csv(\"sales.csv\")  # Start with raw data\n    \n    .assign(\n        # Create revenue column\n        revenue=lambda df: df[\"quantity\"] * df[\"price\"],\n        \n        # Extract month from order_date\n        month=lambda df: pd.to_datetime(df[\"order_date\"]).dt.to_period(\"M\")\n    )\n    \n    # Filter for recent orders\n    .loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Group and aggregate\n    .groupby([\"category\", \"month\"])[\"revenue\"]\n    .sum()\n    \n    # Convert to DataFrame\n    .reset_index()\n    \n    # Sort results\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\nAt this point, the flow is clear, transformations are grouped logically, and we are no longer jumping between variables.  \n\n### Step 4: Clean It Up Further\nSmall tweaks make a big difference.\npython\n\n```\nresult = (\n    pd.read_csv(\"sales.csv\")  # Load data\n    \n    .assign(\n        # Create revenue\n        revenue=lambda df: df[\"quantity\"] * df[\"price\"],\n        \n        # Ensure order_date is datetime\n        order_date=lambda df: pd.to_datetime(df[\"order_date\"]),\n        \n        # Extract month from order_date\n        month=lambda df: df[\"order_date\"].dt.to_period(\"M\")\n    )\n    \n    # Filter relevant time range\n    .loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Aggregate revenue\n    .groupby([\"category\", \"month\"], as_index=False)[\"revenue\"]\n    .sum()\n    \n    # Sort results\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\nNow there are no redundant conversions, there's cleaner grouping and more consistent structure.  \n\n### Step 5: When `pipe()` Becomes Useful\nLet’s say the logic grows. Maybe we only care about high-revenue rows.\nInstead of stuffing that logic into the chain, we extract it:\npython\n\n```\ndef filter_high_revenue(df):\n    # Keep only rows where revenue is above threshold\n    return df[df[\"revenue\"] > 500]\n```\n\nNow we plug it into the pipeline:\npython\n\n```\nresult = (\n    pd.read_csv(\"sales.csv\")  # Load data\n    \n    .assign(\n        # Create revenue\n        revenue=lambda df: df[\"quantity\"] * df[\"price\"],\n        \n        # Convert and extract time features\n        order_date=lambda df: pd.to_datetime(df[\"order_date\"]),\n        month=lambda df: df[\"order_date\"].dt.to_period(\"M\")\n    )\n    \n    # Apply custom transformation\n    .pipe(filter_high_revenue)\n    \n    # Filter by date\n    .loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Aggregate results\n    .groupby([\"category\", \"month\"], as_index=False)[\"revenue\"]\n    .sum()\n    \n    # Sort output\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\nThis is where it starts to feel different. Your code is no longer just a script. Now, it's a sequence of reusable transformations.  \n  \nWhat I like about this process is that you do not need to jump straight to the final version.\nYou can evolve your code gradually.\n  * Start messy.\n  * Reduce variables.\n  * Introduce chaining.\n  * Extract logic when needed.\n\n\nThat is how this pattern actually sticks.  \n  \nNext, let’s talk about a few mistakes I made while learning this so you do not run into the same issues.\n## Common Mistakes (I Made Most of These)\nWhen I started using method chaining, I definitely overdid it.  \nEverything felt cleaner, so I tried to force _everything_ into a chain. That led to some… questionable code.\nHere are a few mistakes I ran into so you do not have to.  \n\n### 1. Over-Chaining Everything\nAt some point, I thought longer chains = better code.  \nNot true.\npython\n\n```\n# This gets hard to read very quickly\ndf = (\n    df\n    .assign(...)\n    .loc[...]\n    .groupby(...)\n    .agg(...)\n    .reset_index()\n    .rename(...)\n    .sort_values(...)\n    .query(...)\n)\n```\n\n  \nYes, it is technically clean. But now it is doing too much in one place.\n**Fix:**\n  * Break your chain when it starts to feel dense.\n  * Group related transformations together\n  * Split logically different steps\n  * Think readability first, not cleverness.\n\n\n### 2. Forcing Logic Into One Line\nI used to cram complex logic into `assign()` or `loc()` just to keep the chain going.\nThat usually makes things worse.\npython\n\n```\n.assign( \n  revenue_flag=lambda df: np.where( \n    (df[\"quantity\"] * df[\"price\"] > 500) & (df[\"category\"] == \"Electronics\"), \n    \"High\", \n    \"Low\" ) )\n```\n\nThis works, but it is not very readable.\n**Fix:**\nIf the logic is complex, extract it.\npython\n\n```\ndef add_revenue_flag(df):\n    df[\"revenue_flag\"] = np.where(\n        (df[\"quantity\"] * df[\"price\"] > 500) & (df[\"category\"] == \"Electronics\"),\n        \"High\",\n        \"Low\"\n    )\n    return df\n\ndf = df.pipe(add_revenue_flag)\n```\n\nCleaner. Easier to test. Easier to reuse.  \n\n### 3. Ignoring `pipe()` for Too Long\nI avoided `pipe()` at first because it felt unnecessary. But without it, you hit a ceiling.\nYou either:  \nbreak your chain  \nor write messy inline logic\n**Fix:**\n  * Use `pipe()` as soon as your logic stops being simple.\n  * It is what turns your code from a script into something modular.\n\n\n### 4. Losing Readability With Poor Naming\nWhen you start using custom functions with `pipe()`, naming matters a lot.\nBad:  \n`def transform(df): ...`\nBetter:  \n`def filter_high_revenue(df): ...`\nNow your pipeline reads like a story:  \n`.pipe(filter_high_revenue)`\nThat small change makes a big difference.  \n\n### 5. Thinking This Is About Shorter Code\nThis one took me a while to realize. Method chaining is not about writing fewer lines. It is about writing code that is easier to read, reason about and come back to later\nSometimes the chained version is longer. That is fine. If it is clearer, it is better.  \n  \nLet’s wrap this up and tie it back to the “intermediate” idea.\n## Conclusion: Leveling Up Your Pandas Game\nIf you’ve followed along, you’ve seen a small shift with a big impact.\nBy thinking in transformations instead of steps, using **method chaining** , **assign()** , and **pipe()** , your code stops being just a collection of lines and becomes a clear, readable flow.\nHere’s what changes when you internalize this pattern:\n  * You can read your code top to bottom without getting lost.\n  * You can reuse transformations easily, making your notebooks more modular.\n  * You can debug and test without tracing dozens of intermediate variables.\n  * You start thinking in pipelines, not just steps.\n\n\nThis is exactly what separates a beginner from an intermediate Pandas user.\nYou’re no longer just “making it work.” You’re designing your analysis in a way that scales, is maintainable, and looks good to anyone who reads it—even future you.\n### Try It Yourself\nPick a messy notebook you’ve been working on and refactor just one part using method chaining.\n  * Start with `assign()` for new columns\n  * Use `loc[]` to filter\n  * Introduce `pipe()` for any custom logic\n\n\nYou’ll be surprised how much clearer your notebook becomes, almost immediately.\nThat’s it. You’ve just unlocked **intermediate Pandas**.\nYour next step? Keep practicing, build your own pipelines, and notice how your thinking about data transforms along with your code.\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[Coding](https://towardsdatascience.com/tag/coding/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Method Chaining](https://towardsdatascience.com/tag/method-chaining/)[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%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F&title=Write%20Pandas%20Like%20a%20Pro%20With%20Method%20Chaining%20Pipelines)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F&title=Write%20Pandas%20Like%20a%20Pro%20With%20Method%20Chaining%20Pipelines)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F&text=Write%20Pandas%20Like%20a%20Pro%20With%20Method%20Chaining%20Pipelines)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](../images/001.jpeg)](https://towardsdatascience.com/three-cases-when-parsing-json-documents-in-a-python-pandas-dataframe-9c9dfea9ec34/)\n## [Three Cases When Parsing JSON Documents In A Python Pandas DataFrame](https://towardsdatascience.com/three-cases-when-parsing-json-documents-in-a-python-pandas-dataframe-9c9dfea9ec34/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nNormalising JSON Objects in Pandas is not difficult if you know these tricks\n[Christopher Tao](https://towardsdatascience.com/author/christophertao/)\nFebruary 14, 20226 min read\n  * [![](../images/002.jpeg)](https://towardsdatascience.com/part-ii-using-a-decision-tree-ddffa4004e47/)\n## [Part II - Using a Decision Tree](https://towardsdatascience.com/part-ii-using-a-decision-tree-ddffa4004e47/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nMLJ is a meta-package for machine learning in Julia. Its first version has been released only in 2019. So its creators could build on more...\n[Roland Schätzle](https://towardsdatascience.com/author/schaetzle.ka/)\nFebruary 22, 202213 min read\n  * [![](../images/003.jpg)](https://towardsdatascience.com/advanced-permutation-importance-to-explain-predictions-ead7de26eed4/)\n## [Advanced Permutation Importance to Explain Predictions](https://towardsdatascience.com/advanced-permutation-importance-to-explain-predictions-ead7de26eed4/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBring Explainability to the Next Level preserving Simplicity\n[Marco Cerliani](https://towardsdatascience.com/author/cerlymarco/)\nFebruary 24, 20216 min read\n  * [![](../images/004.jpeg)](https://towardsdatascience.com/a-hidden-feature-of-python-regex-you-may-not-know-f00c286f4847/)\n## [A Hidden Feature of Python Regex You May Not Know](https://towardsdatascience.com/a-hidden-feature-of-python-regex-you-may-not-know-f00c286f4847/)\n[Programming](https://towardsdatascience.com/category/programming/)\nThe advanced usage of the re.sub() function\n[Christopher Tao](https://towardsdatascience.com/author/christophertao/)\nJuly 19, 20205 min read\n  * [![](../images/005.jpeg)](https://towardsdatascience.com/redefining-nba-player-classifications-using-clustering-36a348fa54a8/)\n## [Redefining NBA Player Classifications using Clustering.](https://towardsdatascience.com/redefining-nba-player-classifications-using-clustering-36a348fa54a8/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBasketball has existed for more than a hundred years, and as the game evolved with new rules and regulations, so did the players. The NBA...\n[Ahmed Jyad](https://towardsdatascience.com/author/ahmedjyad17/)\nNovember 16, 202012 min read\n  * [![](../images/006.jpg)](https://towardsdatascience.com/4-useful-bigquery-sql-functions-you-may-not-know-82e830d994ca/)\n## [4 Useful BigQuery SQL Functions You May Not Know](https://towardsdatascience.com/4-useful-bigquery-sql-functions-you-may-not-know-82e830d994ca/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAnd how to use them\n[Vicky Yu](https://towardsdatascience.com/author/madfordata/)\nJanuary 26, 20233 min read\n  * [![](../images/007.jpeg)](https://towardsdatascience.com/under-the-hood-with-gcps-app-engine-82d862cb3691/)\n## [Under the Hood with GCP's App Engine](https://towardsdatascience.com/under-the-hood-with-gcps-app-engine-82d862cb3691/)\n[Programming](https://towardsdatascience.com/category/programming/)\nA deeper look at how to configure the App Engine and decipher related costs Google's...\n[Andrew Didinchuk](https://towardsdatascience.com/author/appliedarchitect/)\nMay 13, 20217 min read\n  * [![](../images/008.jpeg)](https://towardsdatascience.com/5-python-tricks-that-will-ease-your-life-ed81987ec467/)\n## [5 Python Tricks That Will Ease Your Life](https://towardsdatascience.com/5-python-tricks-that-will-ease-your-life-ed81987ec467/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nMake your scripts more efficient and appealing.\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nAugust 21, 20215 min read\n  * [![](../images/009.png)](https://towardsdatascience.com/analysis-of-car-accidents-in-barcelona-using-pandas-matplotlib-and-folium-73384240106b/)\n## [Analysis of car accidents in Barcelona using Pandas, Matplotlib, and Folium](https://towardsdatascience.com/analysis-of-car-accidents-in-barcelona-using-pandas-matplotlib-and-folium-73384240106b/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nOpen Data Barcelona is Barcelona´s data service which contains around 400 datasets, covering a wide rage of topics such as population...\n[Amanda Iglesias Moreno](https://towardsdatascience.com/author/amandaiglesiasmoreno/)\nSeptember 1, 20199 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/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  * [ ![](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\n\n",
  "metadata": {
    "title": "Write Pandas Like a Pro With Method Chaining Pipelines | Towards Data Science",
    "description": "Master method chaining, assign(), and pipe() to write cleaner, testable, production-ready Pandas code",
    "keywords": null,
    "author": "Ibrahim Salami",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Write Pandas Like a Pro With Method Chaining Pipelines",
    "og:description": "Master method chaining, assign(), and pipe() to write cleaner, testable, production-ready Pandas code",
    "og:url": "https://towardsdatascience.com/this-one-pandas-pattern-separates-beginners-from-intermediate-users/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2026/04/method-chaining.jpg",
    "og:image:width": "985",
    "og:image:height": "537",
    "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": "14 min read",
    "article:published_time": "2026-04-12T09:00:09.000Z",
    "article:modified_time": "2026-04-12T09: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/48c5e48c6d3c/code/block_000.txt",
      "chars": 67
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_001.txt",
      "chars": 465
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_002.txt",
      "chars": 593
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_003.txt",
      "chars": 326
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_004.txt",
      "chars": 610
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_005.txt",
      "chars": 325
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_006.txt",
      "chars": 49
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_007.txt",
      "chars": 31
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_008.txt",
      "chars": 45
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_009.txt",
      "chars": 57
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_010.txt",
      "chars": 205
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_011.txt",
      "chars": 574
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_012.txt",
      "chars": 500
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_013.txt",
      "chars": 605
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_014.txt",
      "chars": 650
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_015.txt",
      "chars": 118
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_016.txt",
      "chars": 662
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_017.txt",
      "chars": 191
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_018.txt",
      "chars": 153
    },
    {
      "language": "txt",
      "file": "attachments/48c5e48c6d3c/code/block_019.txt",
      "chars": 225
    }
  ],
  "images": [
    {
      "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:04:53Z"
    },
    {
      "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:04:54Z"
    },
    {
      "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:04:54Z"
    },
    {
      "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:04:54Z"
    }
  ],
  "audio": [],
  "videos": [
    {
      "url": "https://www.youtube.com/c/TowardsDataScience",
      "kind": "channel_reference",
      "status": "reference_only"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/programming/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/ibrahim.salami/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/coding/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/method-chaining/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/pandas/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/three-cases-when-parsing-json-documents-in-a-python-pandas-dataframe-9c9dfea9ec34/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/christophertao/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/part-ii-using-a-decision-tree-ddffa4004e47/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/schaetzle.ka/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/advanced-permutation-importance-to-explain-predictions-ead7de26eed4/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/computer-science"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=Write+Pandas+Like+a+Pro+With+Method+Chaining+Pipelines&u=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=Write+Pandas+Like+a+Pro+With+Method+Chaining+Pipelines&url=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=Write+Pandas+Like+a+Pro+With+Method+Chaining+Pipelines&url=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%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:31:51Z",
  "source_url": "https://towardsdatascience.com/this-one-pandas-pattern-separates-beginners-from-intermediate-users/",
  "delivery_status": "unverified",
  "discovery_status": "http_403",
  "missing_reason": "源页面未重新核验:http_403；已按保留正文补采图片",
  "repair_error": "",
  "actual_video_files": [],
  "expected_saved_body_images": 4,
  "image_discovery": "saved_markdown",
  "source_body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Programming](https://towardsdatascience.com/category/programming/)\n# Write Pandas Like a Pro With Method Chaining Pipelines\nMaster method chaining, assign(), and pipe() to write cleaner, testable, production-ready Pandas code\n[Ibrahim Salami](https://towardsdatascience.com/author/ibrahim.salami/)\nApril 12, 202614 min read\n![](https://assets.insightmediagroup.io/media/wp-content/uploads/2026/04/method-chaining.jpg)\nGenerated with Gemini AI\nI opened an old notebook recently and immediately closed it.\nNot because it was wrong. The code worked. The numbers checked out.\nBut I had no idea what was going on.\nThere were variables everywhere. `df1`, `df2`, `final_df`, `final_final`. Each step made sense in isolation, but as a whole it felt like I was tracing a maze. I had to read line by line just to understand what I had already done.\nAnd the funny thing is, this is how most of us start with Pandas.\nYou learn a few operations. You filter here, create a column there, group and aggregate. It gets the job done. But over time, your code starts to feel harder to trust, harder to revisit, and definitely harder to share.\nThat was the point I realized something.\nThe gap between beginner and intermediate Pandas users is not about knowing more functions. It is about how you structure your transformations.\nThere is a pattern that quietly changes everything once you see it. Your code becomes easier to read. Easier to debug. Easier to build on.\nIt is called method chaining.\nIn this article, I will walk through how I started using method chaining properly, along with `assign()` and `pipe()`, and how it changed the way I write Pandas code. If you have ever felt like your notebooks are getting messy as they grow, this will probably click for you.\nLearn this step by step with the interactive [Computer Science](https://roadmap.sh/computer-science) roadmap.\n## The Shift: What Intermediate Pandas Users Do Differently\nAt first, I thought getting better at Pandas meant learning more functions.\nMore tricks. More syntax. More ways to manipulate data.\nBut the more I built, the more I noticed something. The people who were actually good at Pandas were not necessarily using more functions than I was. Their code just looked… different.\nCleaner. More intentional. Easier to follow.\nInstead of writing step by step code with lots of intermediate variables, they wrote transformations that flowed into each other. You could read their code from top to bottom and understand exactly what was happening to the data at each stage.\nIt almost felt like reading a story.\nThat is when it clicked for me. The real upgrade is not about _what_ you use. It is about _how_ you structure it.\nInstead of thinking:\n> “What do I do next to this DataFrame?”\nYou start thinking:\n> “What transformation comes next?”\nThat small shift changes everything.\nAnd this is where method chaining comes in.\nMethod chaining is not just a cleaner way to write Pandas. It is a different way to think about working with data. Each step takes your DataFrame, transforms it, and passes it along. No unnecessary variables. No jumping around.\nJust a clear, readable flow from raw data to final result.\nIn the next section, I will show you exactly what this looks like using a real example.\n## The “Before”: How Most of Us Write Pandas\nTo make this concrete, let’s say we want to answer a simple question:\n> Which product categories are generating the most revenue each month?\nI pulled a small sales dataset with order details, product categories, prices, and dates. Nothing fancy.\npython\n\n```\nimport pandas as pd\ndf = pd.read_csv(\"sales.csv\")\nprint(df.head())\n```\n\nOutput\ntext\n\n```\norder_id customer_id     product     category  quantity  price  order_date\n0      1001        C001      Laptop  Electronics         1   1200  2023-01-05\n1      1002        C002  Headphones  Electronics         2    150  2023-01-07\n2      1003        C003    Sneakers      Fashion         1     80  2023-01-10\n3      1004        C001     T-Shirt      Fashion         3     25  2023-01-12\n4      1005        C004     Blender         Home         1     60  2023-01-15\n```\n\nNow, here is how I would have written this not too long ago:\npython\n\n```\n# Create a new column for revenue\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\n\n# Filter for orders from 2023 onwards\ndf_filtered = df[df[\"order_date\"] >= \"2023-01-01\"]\n\n# Convert order_date to datetime and extract month\ndf_filtered[\"month\"] = pd.to_datetime(df_filtered[\"order_date\"]).dt.to_period(\"M\")\n\n# Group by category and month, then sum revenue\ngrouped = df_filtered.groupby([\"category\", \"month\"])[\"revenue\"].sum()\n\n# Convert Series back to DataFrame\nresult = grouped.reset_index()\n\n# Sort by revenue descending\nresult = result.sort_values(by=\"revenue\", ascending=False)\nprint(result)\n```\n\nThis works. You get your answer.\ntext\n\n```\n  category    month  revenue\n1  Electronics  2023-02     2050\n2  Electronics  2023-03     1590\n0  Electronics  2023-01     1500\n8         Home  2023-03      225\n6         Home  2023-01      210\n5      Fashion  2023-03      205\n7         Home  2023-02      180\n4      Fashion  2023-02      165\n3      Fashion  2023-01      155\n```\n\nBut there are a few problems that start to show up as your analysis grows.\nFirst, the flow is hard to follow. You have to keep track of `df`, `df_filtered`, `grouped`, and `result`. Each variable represents a slightly different state of the data.\nSecond, the logic is scattered. The transformation is happening step by step, but not in a way that feels connected. You are mentally stitching things together as you read.\nThird, it is harder to reuse or test. If you want to tweak one part of the logic, you now have to trace where everything is being modified.  \nThis is the kind of code that works fine today… but becomes painful when you come back to it a week later.\nNow compare that to how the same logic looks when you start thinking in transformations instead of steps.\n## The “After”: When Everything Clicks\nNow let’s solve the exact same problem again.\nSame dataset. Same goal.\n> Which product categories are generating the most revenue each month?\nHere’s what it looks like when you start thinking in transformations:\npython\n\n```\nresult = (\npd.read_csv(\"sales.csv\") # Start with raw data\n.assign(\n# Create revenue column\nrevenue=lambda df: df[\"quantity\"] * df[\"price\"],\n\n# Convert order_date to datetime\norder_date=lambda df: pd.to_datetime(df[\"order_date\"]),\n\n# Extract month from order_date\nmonth=lambda df: df[\"order_date\"].dt.to_period(\"M\")\n)\n# Filter for orders from 2023 onwards\n.loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n\n# Group by category and month, then sum revenue\n.groupby([\"category\", \"month\"], as_index=False)[\"revenue\"]\n.sum()\n\n# Sort by revenue descending\n.sort_values(by=\"revenue\", ascending=False)\n)\nprint(result)\n```\n\nSame output. Completely different feel.\ntext\n\n```\n category    month  revenue\n1  Electronics  2023-02     2050\n2  Electronics  2023-03     1590\n0  Electronics  2023-01     1500\n8         Home  2023-03      225\n6         Home  2023-01      210\n5      Fashion  2023-03      205\n7         Home  2023-02      180\n4      Fashion  2023-02      165\n3      Fashion  2023-01      155\n```\n\nThe first thing you notice is that everything flows. There is no jumping between variables or trying to remember what `df_filtered` or `grouped` meant.\nEach step builds on the last one.\nYou start with the raw data, then:\n  * create revenue\n  * convert dates\n  * extract the month\n  * filter\n  * group\n  * aggregate\n  * sort\n\n\nAll in one continuous pipeline.\nYou can read it top to bottom and understand exactly what is happening to the data at each stage.\nThat is the part that surprised me the most.\nIt is not just shorter code. It is _clearer code_.\nAnd once you get used to this, going back to the old way feels… uncomfortable.\nThere are a couple of things happening here that make this work so well.\nWe are not just chaining methods. We are using a few specific tools that make chaining actually practical.\nIn the next section, let’s break those down.\n## Breaking Down the Pattern\nWhen I first saw this style of Pandas code, it looked a bit intimidating.\nEverything was chained together. No intermediate variables. A lot happening in a small space.\nBut once I slowed down and broke it into pieces, it started to make sense.\nThere are really just three ideas carrying everything here:\n  * method chaining\n  * `assign()`\n  * `pipe()`\n\n\nLet’s go through them one by one.  \n\n### Method Chaining (The Foundation)\nAt its core, method chaining is simple. Each step takes a DataFrame, applies a transformation, and returns a new DataFrame. That new DataFrame is immediately passed into the next step.\nSo instead of this:\npython\n\n```\ndf = step1(df) \n\ndf = step2(df) \n\ndf = step3(df)\n```\n\nYou do this:\npython\n\n```\ndf = step1(df).step2().step3()\n```\n\nThat is literally it.\nBut the impact is bigger than it looks.\nIt forces you to think in terms of _flow_. Each line becomes one transformation. You are no longer jumping around or storing temporary states. You are just moving forward.\nThat is why the code starts to feel more readable. You can follow the transformation from start to finish without holding multiple versions of the data in your head.  \n\n###  `assign()` — Keeping Everything in the Flow\nThis is the one that really unlocked chaining for me.\nBefore this, anytime I wanted to create a new column, I would break the flow:\npython\n\n```\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\n```\n\nThat works, but it interrupts the pipeline.\n`assign()` lets you do the same thing without breaking the chain:\npython\n\n```\n.assign(revenue=lambda df: df[\"quantity\"] * df[\"price\"])\n```\n\nAt first, the `lambda df:` part felt weird.\nBut the idea is simple. You are saying:\n“Take the current DataFrame, and use it to define this new column.”\nThe key benefit is that everything stays in one place. You can see where the column is created and how it is used, all within the same flow.\nIt also encourages a cleaner style where transformations are grouped logically instead of scattered across the notebook.  \n\n###  `pipe()` — Where Things Start to Feel Powerful\n`pipe()` is the one I ignored at first.\nI thought, “I can already chain methods, why do I need this?”  \nThen I ran into a problem.\nSome transformations are just too complex to fit neatly into a chain.\nYou either:  \nwrite messy inline logic  \nor break the chain completely\nThat is where `pipe()` comes in.\nIt allows you to pass your DataFrame into a custom function without breaking the flow.\nFor example:\npython\n\n```\ndef filter_high_value_orders(df):\n    return df[df[\"revenue\"] > 500]\n\ndf = (\n    pd.read_csv(\"sales.csv\")\n    .assign(revenue=lambda df: df[\"quantity\"] * df[\"price\"])\n    .pipe(filter_high_value_orders)\n)\n```\n\nNow your logic is cleaner, reusable and easier to test\nThis is the point where things started to feel different for me.\nInstead of writing long scripts, I was starting to build small, reusable transformation steps.\nAnd that is when it clicked.\nThis is not just about writing cleaner Pandas code. It is about writing code that scales as your analysis gets more complex.  \n  \nIn the next section, I want to show how this changes the way you think about working with data entirely.\n## Thinking in Pipelines (The Real Upgrade)\nUp until this point, it might feel like we just made the code look nicer.\nBut something deeper is happening here.\nWhen you start using method chaining consistently, the way you think about working with data begins to change.\nBefore, my approach was very step-by-step.\nI would look at a DataFrame and think:\n> “What do I do next?”\n  * Filter it.\n  * Modify it.\n  * Store it.\n  * Move on.\n\n\nEach step felt a bit disconnected from the last.\nBut with method chaining, that question changes.\nNow it becomes:\n> “What transformation comes next?”\nThat shift is small, but it changes how you structure everything.\nYou stop thinking in terms of isolated steps and start thinking in terms of a flow. A pipeline. Data comes in, gets transformed stage by stage, and produces an output.\nAnd the code reflects that.\nEach line is not just doing something. It is part of a sequence. A clear progression from raw data to insight.\nThis also makes your code easier to reason about.\nIf something breaks, you do not have to scan the entire notebook. You can look at the pipeline and ask:\n  * which transformation might be wrong?\n  * where did the data change in an unexpected way?\n\n\nIt becomes easier to debug because the logic is linear and visible.\nAnother thing I noticed is that it naturally pushes you toward better habits.\n  * You start writing smaller transformations.\n  * You start naming things more clearly.\n  * You start thinking about reuse without even trying.\n\n\nAnd that is where it starts to feel less like “just Pandas” and more like building actual data workflows.\nAt this point, you are not just analyzing data.\nYou are designing how data flows.  \n\n## Real-World Refactor: From Messy to Clean\nLet me show you how this actually plays out.\nInstead of jumping straight from messy code to a perfect chain, I want to walk through how I would refactor this step by step. This is usually how it happens in real life anyway.  \n\n### Step 1: The Starting Point (Messy but Works)\npython\n\n```\ndf = pd.read_csv(\"sales.csv\")  # Load dataset\n\n# Create revenue column\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\n\n# Filter orders from 2023 onwards\ndf_filtered = df[df[\"order_date\"] >= \"2023-01-01\"]\n\n# Convert order_date and extract month\ndf_filtered[\"month\"] = pd.to_datetime(df_filtered[\"order_date\"]).dt.to_period(\"M\")\n\n# Group by category and month, then sum revenue\ngrouped = df_filtered.groupby([\"category\", \"month\"])[\"revenue\"].sum()\n\n# Convert to DataFrame\nresult = grouped.reset_index()\n\n# Sort results\nresult = result.sort_values(by=\"revenue\", ascending=False)\n```\n\nNothing wrong here. This is how most of us start.\nBut we can already see:\n  * too many intermediate variables\n  * transformations are scattered\n  * harder to follow as it grows\n\n\n### Step 2: Reduce Unnecessary Variables\nFirst, remove variables that are not really needed.\npython\n\n```\ndf = pd.read_csv(\"sales.csv\")  # Load dataset\n\n# Create new columns upfront\ndf[\"revenue\"] = df[\"quantity\"] * df[\"price\"]\ndf[\"month\"] = pd.to_datetime(df[\"order_date\"]).dt.to_period(\"M\")\n\nresult = (\n    # Filter relevant rows\n    df[df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Aggregate revenue by category and month\n    .groupby([\"category\", \"month\"])[\"revenue\"]\n    .sum()\n    \n    # Convert to DataFrame\n    .reset_index()\n    \n    # Sort results\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\n  \nAlready better. There are fewer moving parts, and some flow is starting to appear  \n\n### Step 3: Introduce Basic Chaining\nNow we start chaining more deliberately.\npython\n\n```\nresult = (\n    pd.read_csv(\"sales.csv\")  # Start with raw data\n    \n    .assign(\n        # Create revenue column\n        revenue=lambda df: df[\"quantity\"] * df[\"price\"],\n        \n        # Extract month from order_date\n        month=lambda df: pd.to_datetime(df[\"order_date\"]).dt.to_period(\"M\")\n    )\n    \n    # Filter for recent orders\n    .loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Group and aggregate\n    .groupby([\"category\", \"month\"])[\"revenue\"]\n    .sum()\n    \n    # Convert to DataFrame\n    .reset_index()\n    \n    # Sort results\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\nAt this point, the flow is clear, transformations are grouped logically, and we are no longer jumping between variables.  \n\n### Step 4: Clean It Up Further\nSmall tweaks make a big difference.\npython\n\n```\nresult = (\n    pd.read_csv(\"sales.csv\")  # Load data\n    \n    .assign(\n        # Create revenue\n        revenue=lambda df: df[\"quantity\"] * df[\"price\"],\n        \n        # Ensure order_date is datetime\n        order_date=lambda df: pd.to_datetime(df[\"order_date\"]),\n        \n        # Extract month from order_date\n        month=lambda df: df[\"order_date\"].dt.to_period(\"M\")\n    )\n    \n    # Filter relevant time range\n    .loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Aggregate revenue\n    .groupby([\"category\", \"month\"], as_index=False)[\"revenue\"]\n    .sum()\n    \n    # Sort results\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\nNow there are no redundant conversions, there's cleaner grouping and more consistent structure.  \n\n### Step 5: When `pipe()` Becomes Useful\nLet’s say the logic grows. Maybe we only care about high-revenue rows.\nInstead of stuffing that logic into the chain, we extract it:\npython\n\n```\ndef filter_high_revenue(df):\n    # Keep only rows where revenue is above threshold\n    return df[df[\"revenue\"] > 500]\n```\n\nNow we plug it into the pipeline:\npython\n\n```\nresult = (\n    pd.read_csv(\"sales.csv\")  # Load data\n    \n    .assign(\n        # Create revenue\n        revenue=lambda df: df[\"quantity\"] * df[\"price\"],\n        \n        # Convert and extract time features\n        order_date=lambda df: pd.to_datetime(df[\"order_date\"]),\n        month=lambda df: df[\"order_date\"].dt.to_period(\"M\")\n    )\n    \n    # Apply custom transformation\n    .pipe(filter_high_revenue)\n    \n    # Filter by date\n    .loc[lambda df: df[\"order_date\"] >= \"2023-01-01\"]\n    \n    # Aggregate results\n    .groupby([\"category\", \"month\"], as_index=False)[\"revenue\"]\n    .sum()\n    \n    # Sort output\n    .sort_values(by=\"revenue\", ascending=False)\n)\n```\n\nThis is where it starts to feel different. Your code is no longer just a script. Now, it's a sequence of reusable transformations.  \n  \nWhat I like about this process is that you do not need to jump straight to the final version.\nYou can evolve your code gradually.\n  * Start messy.\n  * Reduce variables.\n  * Introduce chaining.\n  * Extract logic when needed.\n\n\nThat is how this pattern actually sticks.  \n  \nNext, let’s talk about a few mistakes I made while learning this so you do not run into the same issues.\n## Common Mistakes (I Made Most of These)\nWhen I started using method chaining, I definitely overdid it.  \nEverything felt cleaner, so I tried to force _everything_ into a chain. That led to some… questionable code.\nHere are a few mistakes I ran into so you do not have to.  \n\n### 1. Over-Chaining Everything\nAt some point, I thought longer chains = better code.  \nNot true.\npython\n\n```\n# This gets hard to read very quickly\ndf = (\n    df\n    .assign(...)\n    .loc[...]\n    .groupby(...)\n    .agg(...)\n    .reset_index()\n    .rename(...)\n    .sort_values(...)\n    .query(...)\n)\n```\n\n  \nYes, it is technically clean. But now it is doing too much in one place.\n**Fix:**\n  * Break your chain when it starts to feel dense.\n  * Group related transformations together\n  * Split logically different steps\n  * Think readability first, not cleverness.\n\n\n### 2. Forcing Logic Into One Line\nI used to cram complex logic into `assign()` or `loc()` just to keep the chain going.\nThat usually makes things worse.\npython\n\n```\n.assign( \n  revenue_flag=lambda df: np.where( \n    (df[\"quantity\"] * df[\"price\"] > 500) & (df[\"category\"] == \"Electronics\"), \n    \"High\", \n    \"Low\" ) )\n```\n\nThis works, but it is not very readable.\n**Fix:**\nIf the logic is complex, extract it.\npython\n\n```\ndef add_revenue_flag(df):\n    df[\"revenue_flag\"] = np.where(\n        (df[\"quantity\"] * df[\"price\"] > 500) & (df[\"category\"] == \"Electronics\"),\n        \"High\",\n        \"Low\"\n    )\n    return df\n\ndf = df.pipe(add_revenue_flag)\n```\n\nCleaner. Easier to test. Easier to reuse.  \n\n### 3. Ignoring `pipe()` for Too Long\nI avoided `pipe()` at first because it felt unnecessary. But without it, you hit a ceiling.\nYou either:  \nbreak your chain  \nor write messy inline logic\n**Fix:**\n  * Use `pipe()` as soon as your logic stops being simple.\n  * It is what turns your code from a script into something modular.\n\n\n### 4. Losing Readability With Poor Naming\nWhen you start using custom functions with `pipe()`, naming matters a lot.\nBad:  \n`def transform(df): ...`\nBetter:  \n`def filter_high_revenue(df): ...`\nNow your pipeline reads like a story:  \n`.pipe(filter_high_revenue)`\nThat small change makes a big difference.  \n\n### 5. Thinking This Is About Shorter Code\nThis one took me a while to realize. Method chaining is not about writing fewer lines. It is about writing code that is easier to read, reason about and come back to later\nSometimes the chained version is longer. That is fine. If it is clearer, it is better.  \n  \nLet’s wrap this up and tie it back to the “intermediate” idea.\n## Conclusion: Leveling Up Your Pandas Game\nIf you’ve followed along, you’ve seen a small shift with a big impact.\nBy thinking in transformations instead of steps, using **method chaining** , **assign()** , and **pipe()** , your code stops being just a collection of lines and becomes a clear, readable flow.\nHere’s what changes when you internalize this pattern:\n  * You can read your code top to bottom without getting lost.\n  * You can reuse transformations easily, making your notebooks more modular.\n  * You can debug and test without tracing dozens of intermediate variables.\n  * You start thinking in pipelines, not just steps.\n\n\nThis is exactly what separates a beginner from an intermediate Pandas user.\nYou’re no longer just “making it work.” You’re designing your analysis in a way that scales, is maintainable, and looks good to anyone who reads it—even future you.\n### Try It Yourself\nPick a messy notebook you’ve been working on and refactor just one part using method chaining.\n  * Start with `assign()` for new columns\n  * Use `loc[]` to filter\n  * Introduce `pipe()` for any custom logic\n\n\nYou’ll be surprised how much clearer your notebook becomes, almost immediately.\nThat’s it. You’ve just unlocked **intermediate Pandas**.\nYour next step? Keep practicing, build your own pipelines, and notice how your thinking about data transforms along with your code.\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[Coding](https://towardsdatascience.com/tag/coding/)[Data Science](https://towardsdatascience.com/tag/data-science/)[Method Chaining](https://towardsdatascience.com/tag/method-chaining/)[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%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F&title=Write%20Pandas%20Like%20a%20Pro%20With%20Method%20Chaining%20Pipelines)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F&title=Write%20Pandas%20Like%20a%20Pro%20With%20Method%20Chaining%20Pipelines)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Fthis-one-pandas-pattern-separates-beginners-from-intermediate-users%2F&text=Write%20Pandas%20Like%20a%20Pro%20With%20Method%20Chaining%20Pipelines)\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/2022/02/1M0g1SS8uMVuuwlpLjoILVA.jpeg)](https://towardsdatascience.com/three-cases-when-parsing-json-documents-in-a-python-pandas-dataframe-9c9dfea9ec34/)\n## [Three Cases When Parsing JSON Documents In A Python Pandas DataFrame](https://towardsdatascience.com/three-cases-when-parsing-json-documents-in-a-python-pandas-dataframe-9c9dfea9ec34/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nNormalising JSON Objects in Pandas is not difficult if you know these tricks\n[Christopher Tao](https://towardsdatascience.com/author/christophertao/)\nFebruary 14, 20226 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/02/1YfvgT04_2VpXHDj8UxnevQ.jpeg)](https://towardsdatascience.com/part-ii-using-a-decision-tree-ddffa4004e47/)\n## [Part II - Using a Decision Tree](https://towardsdatascience.com/part-ii-using-a-decision-tree-ddffa4004e47/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nMLJ is a meta-package for machine learning in Julia. Its first version has been released only in 2019. So its creators could build on more...\n[Roland Schätzle](https://towardsdatascience.com/author/schaetzle.ka/)\nFebruary 22, 202213 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/02/05HFlPQ7yb9DlreRF-scaled.jpg)](https://towardsdatascience.com/advanced-permutation-importance-to-explain-predictions-ead7de26eed4/)\n## [Advanced Permutation Importance to Explain Predictions](https://towardsdatascience.com/advanced-permutation-importance-to-explain-predictions-ead7de26eed4/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBring Explainability to the Next Level preserving Simplicity\n[Marco Cerliani](https://towardsdatascience.com/author/cerlymarco/)\nFebruary 24, 20216 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/07/1i33MOW5JtdYHEWDp7aIBVg.jpeg)](https://towardsdatascience.com/a-hidden-feature-of-python-regex-you-may-not-know-f00c286f4847/)\n## [A Hidden Feature of Python Regex You May Not Know](https://towardsdatascience.com/a-hidden-feature-of-python-regex-you-may-not-know-f00c286f4847/)\n[Programming](https://towardsdatascience.com/category/programming/)\nThe advanced usage of the re.sub() function\n[Christopher Tao](https://towardsdatascience.com/author/christophertao/)\nJuly 19, 20205 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/1QBGNUsHl6A1jsd38tC3evg-scaled.jpeg)](https://towardsdatascience.com/redefining-nba-player-classifications-using-clustering-36a348fa54a8/)\n## [Redefining NBA Player Classifications using Clustering.](https://towardsdatascience.com/redefining-nba-player-classifications-using-clustering-36a348fa54a8/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nBasketball has existed for more than a hundred years, and as the game evolved with new rules and regulations, so did the players. The NBA...\n[Ahmed Jyad](https://towardsdatascience.com/author/ahmedjyad17/)\nNovember 16, 202012 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/01/0LCj3wL8J9LD3U9xN-scaled.jpg)](https://towardsdatascience.com/4-useful-bigquery-sql-functions-you-may-not-know-82e830d994ca/)\n## [4 Useful BigQuery SQL Functions You May Not Know](https://towardsdatascience.com/4-useful-bigquery-sql-functions-you-may-not-know-82e830d994ca/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAnd how to use them\n[Vicky Yu](https://towardsdatascience.com/author/madfordata/)\nJanuary 26, 20233 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/05/1CZhS2d3suVJwojec7S476Q.jpeg)](https://towardsdatascience.com/under-the-hood-with-gcps-app-engine-82d862cb3691/)\n## [Under the Hood with GCP's App Engine](https://towardsdatascience.com/under-the-hood-with-gcps-app-engine-82d862cb3691/)\n[Programming](https://towardsdatascience.com/category/programming/)\nA deeper look at how to configure the App Engine and decipher related costs Google's...\n[Andrew Didinchuk](https://towardsdatascience.com/author/appliedarchitect/)\nMay 13, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/08/1nwpkLEn5xRaBNbI3MYCoLg-scaled.jpeg)](https://towardsdatascience.com/5-python-tricks-that-will-ease-your-life-ed81987ec467/)\n## [5 Python Tricks That Will Ease Your Life](https://towardsdatascience.com/5-python-tricks-that-will-ease-your-life-ed81987ec467/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nMake your scripts more efficient and appealing.\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nAugust 21, 20215 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2019/09/1cRO7lbBfwb7R805TN3y-QQ.png)](https://towardsdatascience.com/analysis-of-car-accidents-in-barcelona-using-pandas-matplotlib-and-folium-73384240106b/)\n## [Analysis of car accidents in Barcelona using Pandas, Matplotlib, and Folium](https://towardsdatascience.com/analysis-of-car-accidents-in-barcelona-using-pandas-matplotlib-and-folium-73384240106b/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nOpen Data Barcelona is Barcelona´s data service which contains around 400 datasets, covering a wide rage of topics such as population...\n[Amanda Iglesias Moreno](https://towardsdatascience.com/author/amandaiglesiasmoreno/)\nSeptember 1, 20199 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/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  * [ ![](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\n\n",
  "body_base_path": "attachments/48c5e48c6d3c/pages/",
  "body_markdown_path": "attachments/48c5e48c6d3c/pages/archived-body.md",
  "local_html": "attachments/48c5e48c6d3c/pages/archived-body.html",
  "body_source": "prior_capture"
}