Data Tables
Business applications rarely keep their data in one giant table. Customers, orders, order lines, and products each describe a different thing at a different grain, so each gets its own table, linked to the others by primary and foreign keys. That design, which Microsoft’s Northwind sample database illustrates, avoids repeated and inconsistent copies, and it gives a report its shape: joins build the view a question needs. Reading a table well starts with three questions: what does one row represent, which columns identify it, and what type is each column? Add a fourth: which values are missing? A null means unknown, not zero, and SQL and pandas each have their own rules for how nulls behave in filters, counts, and sums.
With that foundation, the same table operations appear in both SQL and pandas: choosing columns, filtering rows, sorting, grouping and aggregating, and window calculations that compute across related rows while keeping every row visible. Joins get the most attention, because choosing the wrong join type, duplicated or incomplete keys, or a filter placed after a left join can silently drop rows or inflate totals. The habit to build is to predict the row count before running the query and to check it afterwards. The session closes with why SQL looks the way it does: a declarative language, descended from Codd’s 1970 relational model, where you describe the result you want and the database decides how to produce it.

Listen
| Speaker | Text |
|---|---|
| Alex | Imagine this. You are, uh, you’re presenting a quarterly predictive revenue model to your CEO. High stakes, right? Very high stakes. You’ve spent weeks tuning the hyperparametters. The charts look stunning, and you are ready to impress, but You made one tiny, almost imperceptible mistake in your preprocessing pipeline. Let me guess, a bad join. Exactly, exactly. You joined two tables on a non-unique key, so you just accidentally duplicated every single transaction in your data set, inflated projected revenue by like $80 million and essentially ruined your credibility. before the meeting even started. Yeah, |
| Sam | that dashboard nightmare you just described, that happens every single day in the industry. It |
| Alex | really does. And if you are a data science and analytics graduate student listening to this right now, and you are, you know that the sexiest parts of artificial intelligence rest entirely on this invisible, unforgiving foundation. |
| Sam | Right. The organizing, cleaning, and querying of tables. |
| Alex | Exactly. So today our mission is to explore the fundamental architecture of that foundation. We’re decoding why the concept of related tables, which was popularized way back in the 1970s, remains the absolute gold standard for data scientists today. |
| Sam | And crucially, we are bridging that philosophy directly into modern Python workflows using pandas. Because before anyone can build some world changing neural network, they have to face the absolute reality of wrangling the data. |
| Alex | Totally. We’re going to look at the intuition behind tables, the philosophical differences between SQL and pandas, how they handle operations, and the absolute minefield that is joining data sets together, |
| Sam | because understanding not just what a query does, but why the underlying systems behave the way they do, that is what separates a junior analyst from a senior data scientist. So |
| Alex | true. Let’s start at the absolute bedrock, which is the concept of the grain, which, I mean, it sounds a bit like woodworking, but in data architecture, if you get this wrong, your entire model is compromised from day one. |
| Sam | It really is the single most important question you can ask when you inherit a new data set. You have to ask, what does one single row represent? That is the grain. |
| Alex | Because the table just organizes observations into rows and attributes into columns, but if you don’t know the grain, you don’t actually know what your data means, |
| Sam | right? If you assume a row represents a single customer order, but the grain is actually, say, an individual line item on that order, |
| Alex | oh man, then every time you sum up the flat shipping costs, you are going to be multiplying those costs artificially for every item in the box. |
| Sam | Exactly. To ground this. Think about Microsoft’s classic North Wind sample database. Anyone who has taken a database 101 class has probably queried North Wind. Oh, absolutely, |
| Alex | the classic mock company. It has tables for customers, orders, order details, products, and suppliers, and they all have vastly different grains, right? Right. |
| Sam | A row in the customer’s table represents one unique human being. But a row in the products table represents one catalog item, |
| Alex | and business reality is incredibly messy. Like a customer can place many orders. An order can contain 50 different products. Yeah, |
| Sam | and a single product can be sourced from a dozen different suppliers. The relationships are just this giant web. |
| Alex | Which, you know, begs the obvious question, why build a web at all? Why not just dump all of this into one massive million row flat spreadsheet? |
| Sam | Oh, the giant spreadsheet, |
| Alex | right? Just one endless table of sale lines showing the customer’s home address, the exact time they ordered, the product description, the supplier’s corporate name, the quantity. Quantity and the price. I mean, |
| Sam | that is the instinct of every single person who opens Excel for the first time. But in a massive business application, it is a recipe for absolute systemic collapse. Why is that? Well, imagine a popular product’s catalog information, its weight, it’s description, its manufacture. Repeating across 10 million transaction rows or a customer’s address repeated for every single individual item they have ever purchased over a 5-year period. |
| Alex | OK, let’s unpack this. Keeping everything in one giant table is like having to manually update a friend’s new phone number in 100 different text threads instead of just updating their main contact card. |
| Sam | That is a perfect analogy. Or like hard coding a state tax rate into a 1000 different Python scripts. Instead of just importing it from one central configuration file. Oh |
| Alex | yeah, if the tax rate changes, you are suddenly hunting down 1000 different scripts to fix it. And if you miss even one, your application is generating inconsistent data. Spot |
| Sam | on. By separating these distinct facts into related tables, a process database engineers call normalization. You eliminate unnecessary repetition and prevent those update anomalies. So |
| Alex | if a customer moves across the country, you update their address in exactly one place, the customer’s table, |
| Sam | right? And every future query that links to that customer instantly pulls the correct updated address. |
| Alex | But there is an even more critical business distinction preserved by normalization, specifically when we look at why the North Wind database separates the order details table from the products table. |
| Sam | Yes, the pricing issue, |
| Alex | right? It clicked for me immediately when I was reading the source notes. It is basically about time travel and pricing. |
| Sam | It’s the perfect showcase of why normalization matters. You have to preserve the difference between the current catalog price, which lives in the products table, and the actual price charged at the exact moment of purchase, |
| Alex | which lives in the order details table. |
| Sam | Exactly. Because if you only had one giant denormalized table and your company raised the price of a product today, updating that single row might accidentally rewrite the historical revenue of past sales from 3 years ago. |
| Alex | Wow, yeah, you would literally be rewriting history. The catalog price today and the price someone paid on a Black Friday sale 3 years ago, those are two completely different facts. |
| Sam | Storing each fact with a specific entity or event it actually describes, that is the heart of normalization. |
| Alex | So we have these perfectly separated logical tables. Now we have to talk to them, which brings us to the great handshake between Sequel and pandas. |
| Sam | Yeah, to really grasp how SQL and Pandas interact today, we have to look back at the breakthrough that made it all possible. Back in 1970, a researcher at IBM named EF Cod published a paper introducing the relational model of data. |
| Alex | 1970. OK, |
| Sam | yeah, and his ultimate goal was a concept called data independence. |
| Alex | Data independence. What did that actually mean in the context of 1970s computing? |
| Sam | Well, back then, if you wanted to query data, you essentially had to write procedural code that understood the physical mechanics of the storage device. |
| Alex | Wait, really? Like knowing where it physically lived? |
| Sam | Yeah, you had to tell the computer, go to this physical spinning tape, read these sectors, loop through them, and pull out this data. Cod argued that applications should be able to ask logical questions about the data without needing to know a thing about the physical storage paths. |
| Alex | OK, I love that. You shouldn’t have to be a mechanical engineer to order off a menu. You just tell the waiter what you want. |
| Sam | Exactly. And that led to the creation of SQL. SQL is a declarative language. You tell the database what result you want, like select the average order amount from the sales table where the year is 2025, |
| Alex | and the database figures out the rest, |
| Sam | right? Its internal optimizer figures out the most computationally efficient, how to go fetch it. It creates the execution plan for you. |
| Alex | But pandas in Python is the exact opposite. It’s procedural. When you write Python, you are writing explicit method chains, telling the computer exactly what operations to execute in what specific order. That’s right, which makes me wonder if SQL is so highly optimized and its engine does all the brilliant execution planning for us, why do data scientists even bother pulling data into pandas at all? Why not just build everything in SQL? |
| Sam | That’s a great question. Well, Sequel is an absolute powerhouse for set-based operations and retrieving data. It was never designed for complex statistical modeling, machine learning algorithms, or advanced sequential data manipulation. Oh, |
| Alex | I see. And |
| Sam | plus, there’s a fundamental difference in architecture. SQL databases usually operate on massive disk storage. They can crunch terabytes of data. Pandas loads data entirely into your computer’s RAM. |
| Alex | Ah, so it is a tag team. Sequel acts as the giant funnel. You use SQL on the server to join the massive tables, filter out the junk, and aggregate billions of rows down to a dense 10 megabyte summary table. |
| Sam | Exactly. Then you pass that to pandas. Pandas integrate seamlessly with the rest of the Python ecosystem like NumPy, Psychki Learn, Tensorflow. |
| Alex | So you use SQL for the heavy lifting to get the data into the right shape and pandas in memory to actually train the model. You’ve got |
| Sam | it. But because they were built with completely different philosophies, they have some distinct personality clashes, especially regarding data types. |
| Alex | Oh, definitely, like how SQL uses things like numeric 10.2, which guarantees precise decimal arithmetic, which is crucial if you are dealing with financial transactions, |
| Sam | right? But pandas typically defaults to float 64, which uses floating point arithmetic. |
| Alex | And any grad student who has ever tried to add 0.1 and 0.2 in Python and gotten 00.3000000004 knows exactly why floating point math can cause major headaches in financial reporting. |
| Sam | It’s infuriating. |
| Alex | It’s, |
| Sam | but you know, an even more dangerous trap is how these two systems handle missing data, |
| Alex | the null trap. Let’s crown this with a specific scenario from the source notes. We have three customers Ada, Ben, and Cy. OK, |
| Sam | Ada, Ben, and Cy. |
| Alex | Ada has two orders. Ben has 1 order, but for some reason, the amount column is completely blank. Cy has no orders at all. We also have a weird orphaned order belonging to customer 99, but customer 99 doesn’t exist in our customer database. |
| Sam | Welcome to the reality of messy real world data. And before we do any math on this, here is the absolute golden rule you must internalize. Let’s hear it. Missing is not zero. An empty string is not null. The literal text, N U L L is not null. Null represents a completely unknown void. |
| Alex | So in Ben’s case, we know he placed an order, but we have absolutely no idea how much money he spent. |
| Sam | Exactly. Missing is not zero. If you are doing lifetime value calculations, treating a missing purchase amount as a $0 purchase fundamentally alters your statistics. |
| Alex | Right? And the two systems query this void differently. If you want to find missing amounts in SQL, you cannot write where amount equals null. |
| Sam | No, because a mathematical equality check against an unknown value evaluates to unknown. It will just fail. You have to explicitly use where amount is null. |
| Alex | And in pandas, you use the dot is an a method, |
| Sam | right? But the real danger happens when we try to aggregate. Let’s say we want to sum up all the revenue. The known amounts for Ada and customer 99 equal 180. What happens to Ben’s null order? |
| Alex | OK, so SQL’s sum function is designed to ignore null inputs entirely. It just skips Ben’s empty value and sums the rest. |
| Sam | Yes. However, if all the inputs for a specific group are null, Sequel returns null. It basically throws its hands up and says, I don’t know the sum, |
| Alex | which is mathematically honest. |
| Sam | But Pandas does something terrifying. |
| Alex | It really does. |
| Sam | Pandas using the standard dot sum method also skips missing values by default. But if you ask pandas to sum a group where every single value is missing, |
| Alex | let me guess, |
| Sam | it will accidentally return zero. |
| Alex | Wait, seriously? So if I use pandas to sum up Ben’s purchases, it will confidently report that Ben spent exactly $0. That completely breaks our rule. |
| Sam | He does. Unless you explicitly tell pandas not to, to force pandas to behave like sequel and return a missing total for an all missing group, you have to pass a parameter. Min count equals one. |
| Alex | Min count equals one. |
| Sam | Yeah, this tells Python only calculate a sum if there is at least one valid number. Otherwise, return a null. That one little parameter will save you days of debugging false zeros in your data frames. That |
| Alex | is wild. OK, so once you have safely navigated the nulls and pulled your data from SQL into Python, you actually have to shape it. You can’t just feed raw tables into a regression model. We have to trim the fat. |
| Sam | Right? And that introduces the core operations, projection, filtering, sorting, and grouping. Projection is just selecting which columns you care about. In SQL, it’s the select clause. In pandas, you just pass a list of column names inside brackets. |
| Alex | And filtering is choosing the rows. Sequel uses the wee clause. Pandas uses dot lock with a boolean mask, |
| Sam | which sounds complex, but it basically just means passing a list of truths and falses over your data frame, |
| Alex | right? Acting like a sieve to hide the rows you don’t want. |
| Sam | Exactly. Sorting is straightforward too. Uh, order by in SQL or dot sword values in Python. But grouping is where data gets its analytical power. |
| Alex | Grouping partitions your rows by a key, like grouping all transactions by customer ID. |
| Sam | And when you group, there is a massive difference between counting rows and counting values. Oh, |
| Alex | a critical difference. Let’s look at Bennigan, who has one order with a missing amount. In Sequel. If you write count star, it counts all the rows in the group regardless of null, so it returns one, |
| Sam | right? But if you write count amount, It only counts rows where the amount actually exists, so it returns zero. |
| Alex | And Pandas handles this with dot size to count raw rows and dot count to count non-null values. But wait, order of operations matters here, right? When exactly does the filtering happen during a group by? |
| Sam | Ah, in sequel, a wee clause filters rows before they are grouped. But what if you want to filter the groups themselves? Say you only want to look at customers whose average order value is over $100. You can’t use where for that. No, you have to use the having clause, which evaluates after the aggregation is complete. In pandas, there isn’t a dedicated keyword. You simply have to deliberately structure your explicit method chain. To filter before or after your dot group by |
| Alex | call. Makes sense. That covers basic aggregation, but there is a slightly more advanced concept in the notes that bridges the gap between raw rows and aggregated groups, window calculations. Oh, |
| Sam | Window functions are incredibly powerful. See. A standard aggregate reduces the number of rows. If you have 10 orders for a customer and you take the average, you are left with one single row representing that average. |
| Alex | Here’s where it gets really interesting. |
| Sam | It’s like taking a group photo and blurring everyone together into a single composite blob. You see the average, but you lose the individuals. |
| Alex | Exactly. But a window calculation is like taking a group photo where everyone remains perfectly in focus, but they are all holding up a sign that displays the group’s average height. You get the aggregate data, but you don’t lose sight of each individual person attached to the original row. |
| Sam | That visualization hits the nail on the head. Let’s say you want to calculate what percentage each individual order contributes to a customer’s total lifetime spend. You need the individual order amount and the aggregate total sitting side by side in the same row. OK, |
| Alex | so how do we do that? |
| Sam | In SQL, you achieve this using the over clause, specifically over partition by customer ID. |
| Alex | So for Ada, who has an order for 100 and an order for 50, the query keeps both of her distinct order rows intact, but appends a new column next to them, saying her total is 150. |
| Sam | Yes, both of her original orders remain entirely visible. In Pandas, you achieve this using .group by, customer ID amount.transform sum. |
| Alex | The dot transform method, |
| Sam | right? It calculates the aggregate, but then broadcasts that value back to match the original shape and length of the data frame. It is the ultimate tool for running totals, moving averages, or standardizing features for a machine learning model. |
| Alex | Which brings us to the final, most dangerous phase of data tables. We spent the beginning of this deep dive explaining why we separate data into normalized tables. Now we have to talk about how we put them back together. Joins, joins. |
| Sam | A join combines rows from two tables according to a key relationship, like matching the customer ID in the orders table to the customer ID in the customer’s table. But the type of join you choose entirely dictates how the database handles the unmatched rows. OK, |
| Alex | let’s run through these using our data again. Ada, Ben, Psy, and the orphaned customer 99 order. |
| Sam | OK, the most restrictive is the inner join. It acts like a strict bouncer. It only keeps perfect matches. It keeps Ada and Ben because they have orders and exist in the customer database, |
| Alex | but it drops the orphaned order 4 because there is no customer 99, |
| Sam | right? And it dropped psy because even though she is a customer, she has no orders. |
| Alex | So inner joins are great when you only want complete data. What about the left join? |
| Sam | The left join is your baseline for preserving primary records. It keeps everything from the left table, in this case, all customers, and pulls in matching data from the right table, the |
| Alex | orders. This is incredible for finding churn or missing action, right, because sy stays in the results, but since she has no orders, all her order columns are just filled with nulls. You can literally filter for those nulls to find every customer who has never bought anything, |
| Sam | precisely. |
| Alex | And the right joint is just the inverse. It keeps all the orders on the right, meaning the orphaned order 4 stays, but gets nulls for the customer details. |
| Sam | Wait, if left keeps all the left and right keeps all the right, what does the full outer joint do? Does it just create a massive Frankenstein table full of nulls on both sides? Why would a data scientist ever want that? |
| Alex | A full outer joint keeps everything. The orphaned |
| Sam | orders and the orderless customers. You usually use this when you are merging two independent data sets where neither is the absolute source of truth. Oh, |
| Alex | like comparing an internal sales database with a third party payment gateway report. |
| Sam | Exactly. You want to see the transactions that match the ones missing from your database and the ones missing from the gateway. |
| Alex | That makes a lot of sense. And the final one, the crossjo, |
| Sam | the Cartesian product. A cross-join pairs every single row on the left with every single row on the right. If you have 4 orders and 3 customers, you get 12 pairs. |
| Alex | But if you have a million orders and a million customers, |
| Sam | you get a 1 trillion rows and you crash the database server. You only do this intentionally to generate a grid of all possible combinations like checking every product’s availability in every single retail store. |
| Alex | OK, so the mechanics make sense, but earlier we talked about a dashboard nightmare where a bad joint inflated revenue by $80 million. How does that actually happen in practice? |
| Sam | The most common pitfall, multiplying rows. A join is basically a matching engine. And if you join on a key that isn’t completely unique on the right side, say someone accidentally entered two identical records for customer 10 in the customer’s table. |
| Alex | Oh, I see where this is going. |
| Sam | The database will duplicate the left row for every single match it finds. |
| Alex | So suddenly, Ada’s single $100 order turns into 2 $100 rows. Your sum function calculates $200 and boom, you report fake revenue. |
| Sam | Exactly. The best prevention in PANDAS is utilizing the validate parameter. By writing validate equals many to 1 during your merge, Python will verify the right side keys are strictly unique before executing. If they aren’t, it throws a hard error instead of silently corrupting your data. |
| Alex | I will gladly take a hard error over explaining fake revenue to a CEO. What about ambiguous columns? Well, |
| Sam | imagine both your orders table and your customers table have a column simply named status. One means order shipment status, the other means customer account status. If you join them without resolving the name collision, Sequel might crash with an ambiguous column error, and Pandas, Pandas will silently execute, but it will rename them status X and status Y. |
| Alex | Uh, status.X is the bane of every data analyst’s existence. You look at your data frame a week later and have no idea which is which. |
| Sam | The fix is explicit aliases. In SQL declare O status as order status. In pandas, pass the suffixes argument during the merge, like suffixes order customer. So your output remains readable. |
| Alex | OK. I want to dive into one final pitfall before we wrap up, the outer join trap. The logic here is incredibly subtle, but it completely destroys data sets. |
| Sam | Oh yeah, this trap catches even seasoned engineers. Let’s say you want a list of all orders, but you only want to attach the customer’s name if their account status is active. Because you want to keep all orders, you decide to use a left join from orders to customers. |
| Alex | Makes total sense. Left join preserves all the orders on the left, even the orphaned order 4. |
| Sam | But then at the very end of your SQL query, You try to filter for the active accounts by adding a wear clause, where ct status equals active. |
| Alex | Wait, I see it. Order 4 doesn’t have a matching customer, so its C status column is filled with a null. |
| Sam | And as we established earlier, null does not equal active. So |
| Alex | the wear clause evaluates to false and order 4 gets deleted from the final result. |
| Sam | You just secretly turned your left joint back into an inner joint. You dropped the very records you used a left joint to protect in the first place. Wow. |
| Alex | How do you filter the right table without triggering the trap? |
| Sam | In SQL, you put the eligibility test up in the on clause before the join fully executes. So, on O.customer ID equals C.customer ID and C status equals active. In pandas, you filter the right-hand customer’s data frame to only include active accounts before you merge it with the order’s data frame. |
| Alex | That is a subtle but massive structural difference. If we step back and look at this entire journey, we’ve explored how tables are normalized, how SQL and Pandas tag team the declarative and procedural workloads, how to carefully handle nulls, and the exact pipeline of joining, grouping, and windowing. You really cannot build the roof of machine learning if you don’t fully comprehend this foundation. |
| Sam | It is the prerequisite to everything else. But you know, there is a fascinating historical irony to all of this. EF Cod established this relational normalized model in 1970 because disk storage was astronomically expensive. Eliminating redundant data wasn’t just good design, it was an absolute financial necessity to save megabytes of space. |
| Alex | But wait, we don’t live in 1970. We live in an era of massive cloud data lakes where storage is practically free. It’s the compute power, the massive server clusters required to perform billion row joins over and over again that cost companies millions of dollars today, |
| Sam | which completely flips the underlying economics. |
| Alex | So if storage is basically free and joining normalized tables is incredibly expensive, Does that mean we might actually want those massive flat denormalized spreadsheets now? |
| Sam | In many modern analytical databases like Snowflake or BigQuery, yes, we are actively returning to giant denormalized tables for our final analytical models because reading one massive table is computationally cheaper than joining five normalized ones. The rules EF Cod wrote 50 years ago are being rewritten by the economics of the cloud. |
| Alex | A true paradigm shift to keep you up at night. We hope you enjoyed this deep dive into the architecture of data tables. Before you go wire up your next predictive model, check your joins, use your suffixes, and remember, missing is never zero. Thanks for listening. |
Presentation
Read
- Tabular Data (source document for podcast)
Hands-on
Notebooks in 07-Data-Tables