{"id":16503,"date":"2026-07-08T12:40:42","date_gmt":"2026-07-08T12:40:42","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=16503"},"modified":"2026-07-08T12:40:42","modified_gmt":"2026-07-08T12:40:42","slug":"sql-vs-pandas-vs-ai-brokers-which-solves-analytics-issues-greatest","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=16503","title":{"rendered":"SQL vs Pandas vs AI Brokers: Which Solves Analytics Issues Greatest?"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"post-\">\n<p><img decoding=\"async\" alt=\"SQL vs Pandas vs AI Agents\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi_sql-vs-pandas-vs-ai-agents-2.png\"\/><br \/>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Introduction<\/h2>\n<p>\u00a0<br \/>We gave the identical three interview questions from <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.stratascratch.com\/\" target=\"_blank\">StrataScratch<\/a><\/strong> to SQL, <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/pandas.pydata.org\/\" target=\"_blank\">Pandas<\/a><\/strong>, and a <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/claude.ai\/\" target=\"_blank\">Claude<\/a><\/strong> agent. Each piece of code executed towards the identical dataset, and each timing quantity is a median over 500 runs. The agent&#8217;s solutions are precisely what Claude generated in response to a documented immediate, as a substitute of a hypothetical instance of what an agent would possibly produce.<\/p>\n<p>The comparability runs throughout eight dimensions: pace, accuracy, explainability, debugging, scalability, flexibility, hallucination danger, and manufacturing readiness. The three questions span Straightforward, Medium, and Exhausting issue ranges. The more durable the query, the extra the variations between SQL, Pandas, and the agent turn out to be seen.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>How We Ran This Comparability<\/h2>\n<p>\u00a0<br \/>The three questions come from the StrataScratch interview financial institution and canopy Straightforward, Medium, and Exhausting issue ranges. SQL ran on <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.sqlite.org\/\" target=\"_blank\">SQLite<\/a><\/strong> in-memory, timed over 500 runs, with the median taken. Pandas ran on the identical dataset in <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.python.org\/\" target=\"_blank\">Python<\/a><\/strong> 3.12, additionally over 500 runs. The agent is Claude&#8217;s <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.anthropic.com\/news\/claude-sonnet-4-6\" target=\"_blank\">claude-sonnet-4-6<\/a><\/strong>, known as through the <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.anthropic.com\/api\" target=\"_blank\">Anthropic API<\/a><\/strong>.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"SQL vs Pandas vs AI Agents\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi_sql-vs-pandas-vs-ai-agents-3.png\"\/><br \/>\u00a0<\/p>\n<p>Every query received its personal schema-grounded consumer immediate that included the desk names, column names, and some pattern rows. The system immediate under stayed the identical for all three calls. Agent response occasions are measured from the time the request is shipped to the primary token obtained.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Easy Retrieval: All Three Agree<\/h2>\n<p>\u00a0<br \/>For the <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/platform.stratascratch.com\/coding\/9787-user-scroll-up-events?code_type=1&amp;utm_source=blog&amp;utm_medium=click&amp;utm_campaign=kdn+sql+vs+pandas+vs+ai+agents\" target=\"_blank\">first interview query from Meta<\/a>, customers are requested to search out each consumer who carried out at the very least one <code>scroll_up<\/code> occasion and return the distinct consumer IDs. The info lives in a single desk known as <code>facebook_web_log<\/code>.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Knowledge<\/h4>\n<p>This is the <code>facebook_web_log<\/code> desk.<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">user_id<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">timestamp<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">motion<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-04-25 13:30:15<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">page_load<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-04-25 13:30:18<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">page_load<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-04-25 13:30:40<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">scroll_down<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-04-25 13:30:45<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">scroll_up<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">\u2026<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">\u2026<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">\u2026<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-04-25 13:30:40<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">page_exit<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQL Coding Resolution (0.002 ms)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>SELECT DISTINCT user_id&#13;\nFROM facebook_web_log&#13;\nWHERE motion = 'scroll_up';<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Coding Resolution (0.40 ms)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>import pandas as pd&#13;\noutcome = (&#13;\n    facebook_web_log[facebook_web_log['action'] == 'scroll_up']&#13;\n    .drop_duplicates(subset=\"user_id\")[['user_id']]&#13;\n)<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Agent Immediate<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>Desk: facebook_web_log (user_id INTEGER, motion TEXT, timestamp TEXT)&#13;\nPattern rows:&#13;\n(1, 'scroll_up',   '2019-01-01 00:00:00')&#13;\n(2, 'scroll_down', '2019-01-01 00:01:00')&#13;\n(3, 'like',        '2019-01-01 00:03:00')&#13;\n(2, 'scroll_up',   '2019-01-01 00:04:00')&#13;\nQuery: Discover all customers who carried out at the very least one scroll_up occasion.&#13;\nReturn distinct consumer IDs.<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Agent Output (2 s)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>SELECT DISTINCT user_id&#13;\nFROM facebook_web_log&#13;\nWHERE motion = 'scroll_up';<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Output: All three return customers 1 and a couple of.<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>On a single-filter drawback, the agent matches SQL precisely. The one actual danger at this issue is column naming. With out the schema within the immediate, <code>motion<\/code> would possibly come again as <code>event_type<\/code> or <code>event_name<\/code>, which returns nothing and throws no error.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Multi-Step Aggregation: The place Schema Grounding Issues Most<\/h2>\n<p>\u00a0<br \/>The <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/platform.stratascratch.com\/coding\/9792-user-feature-completion?code_type=1&amp;utm_source=blog&amp;utm_medium=click&amp;utm_campaign=kdn+sql+vs+pandas+vs+ai+agents\" target=\"_blank\">second query<\/a> is about product characteristic completion. An app tracks how far every consumer will get by means of a set of product options, the place each characteristic has a hard and fast variety of steps.<\/p>\n<p>The duty is to calculate the common completion share for every characteristic throughout all customers, the place a consumer&#8217;s completion is their most step reached divided by the whole steps for that characteristic, occasions 100. Customers who&#8217;ve by no means began a characteristic are counted as 0% full.<\/p>\n<p>Two tables feed this: <code>facebook_product_features<\/code>:<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">feature_id<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">n_steps<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">5<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">7<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p>and <code>facebook_product_features_realizations<\/code>.<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">feature_id<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">user_id<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">step_reached<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">timestamp<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-03-11 17:15:00<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-03-11 17:22:00<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">3<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-03-11 17:25:00<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">4<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-03-11 17:27:00<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">&#8230;<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">&#8230;<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">&#8230;<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">&#8230;<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">3<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2019-04-05 13:00:07<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQL Coding Resolution (0.007 ms)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>WITH max_step AS (&#13;\n    SELECT&#13;\n        feature_id,&#13;\n        user_id,&#13;\n        MAX(step_reached) AS max_step_reached&#13;\n    FROM facebook_product_features_realizations&#13;\n    GROUP BY feature_id, user_id&#13;\n),&#13;\ncalc_per_feature AS (&#13;\n    SELECT&#13;\n        feats.feature_id,&#13;\n        n_steps,&#13;\n        max_step_reached,&#13;\n        COALESCE(max_step_reached, 0) * 1.0 \/ n_steps AS share_of_completion&#13;\n    FROM facebook_product_features feats&#13;\n    LEFT OUTER JOIN max_step&#13;\n        ON feats.feature_id = max_step.feature_id&#13;\n)&#13;\nSELECT&#13;\n    feature_id,&#13;\n    AVG(share_of_completion) * 100 AS avg_share_of_completion&#13;\nFROM calc_per_feature&#13;\nGROUP BY feature_id;<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Coding Resolution (2.05 ms)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>import pandas as pd&#13;\n# max step per consumer per characteristic&#13;\nmax_step = (&#13;\n    facebook_product_features_realizations&#13;\n    .groupby(['feature_id', 'user_id'])['step_reached']&#13;\n    .max()&#13;\n    .reset_index()&#13;\n)&#13;\n&#13;\n# be a part of to options, fill customers who by no means began with 0&#13;\ndf = pd.merge(&#13;\n    facebook_product_features,&#13;\n    max_step,&#13;\n    how='outer',&#13;\n    on='feature_id'&#13;\n).fillna(0)&#13;\n&#13;\n# completion % per user-feature row&#13;\ndf['share_of_completion'] = (df['step_reached'] \/ df['n_steps']) * 100&#13;\n&#13;\n# common per characteristic&#13;\noutcome = (&#13;\n    df.groupby('feature_id')['share_of_completion']&#13;\n    .imply()&#13;\n    .to_frame('avg_share_of_completion')&#13;\n    .reset_index()&#13;\n)<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Agent Immediate<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>Tables:&#13;\n- facebook_product_features (feature_id INTEGER, n_steps INTEGER)&#13;\n- facebook_product_features_realizations&#13;\n  (feature_id INTEGER, user_id INTEGER, step_reached INTEGER, timestamp TEXT)&#13;\nQuery: For every characteristic, calculate the common completion share&#13;\nthroughout all customers. A consumer's completion = max(step_reached) \/ n_steps * 100.&#13;\nCustomers who by no means began rely as 0% completion.&#13;\nReturn: feature_id, avg_share_of_completion.<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Agent Output (3 s)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>WITH user_max_steps AS (&#13;\n    SELECT feature_id, user_id, MAX(step_reached) AS max_step&#13;\n    FROM facebook_product_features_realizations&#13;\n    GROUP BY feature_id, user_id&#13;\n)&#13;\nSELECT&#13;\n    f.feature_id,&#13;\n    ROUND(AVG(COALESCE(ums.max_step, 0) * 100.0 \/ f.n_steps), 2) AS avg_share_of_completion&#13;\nFROM facebook_product_features f&#13;\nLEFT JOIN user_max_steps ums ON f.feature_id = ums.feature_id&#13;\nGROUP BY f.feature_id&#13;\nORDER BY f.feature_id;<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Output: All three return the identical numbers.<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">feature_id<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">avg_share_of_completion<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">80<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">0<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">76.19<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p>The agent received it proper right here as a result of the immediate mentioned: &#8220;Customers who by no means began rely as 0% completion.&#8221; That phrase is load-bearing. With out it, the agent writes an inside be a part of \u2014 which drops non-starters \u2014 and each common goes up. That failure is silent. The numbers come again clear, and so they&#8217;re flawed. You&#8217;d must know the anticipated output to catch it.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>A number of Tables and Window Logic: All Three Right, One A lot Slower<\/h2>\n<p>\u00a0<br \/>The <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/platform.stratascratch.com\/coding\/10084-cum-sum-energy-consumption?utm_source=blog&amp;utm_medium=click&amp;utm_campaign=kdn+sql+vs+pandas+vs+ai+agents\" target=\"_blank\">third query<\/a> covers Meta&#8217;s information heart vitality consumption throughout three areas. Every area has its personal desk: <code>fb_eu_energy<\/code>, <code>fb_na_energy<\/code>, and <code>fb_asia_energy<\/code>.<\/p>\n<p>The duty is to mix them, sum consumption by date, and produce two derived columns: the cumulative working complete and that complete as a share of the grand complete, rounded to an entire quantity.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Knowledge<\/h4>\n<p>Every regional desk has the identical form.<\/p>\n<p><code>fb_eu_energy<\/code>:<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">recorded_date<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">consumption<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-01<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">400<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-02<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">350<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-03<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">500<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-04<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">500<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-07<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">600<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p><code>fb_na_energy<\/code>:<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">recorded_date<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">consumption<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-01<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">250<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-02<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">375<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-03<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">600<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-06<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">500<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-07<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">250<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p><code>fb_asia_energy<\/code>:<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">recorded_date<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">consumption<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-01<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">400<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-02<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">400<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-04<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">675<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-05<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1200<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-06<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">750<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-07<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">400<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQL Coding Resolution (0.010 ms)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>WITH total_energy AS (&#13;\n    SELECT recorded_date, consumption FROM fb_eu_energy&#13;\n    UNION ALL&#13;\n    SELECT recorded_date, consumption FROM fb_asia_energy&#13;\n    UNION ALL&#13;\n    SELECT recorded_date, consumption FROM fb_na_energy&#13;\n),&#13;\nenergy_by_date AS (&#13;\n    SELECT&#13;\n        recorded_date,&#13;\n        SUM(consumption) AS total_energy&#13;\n    FROM total_energy&#13;\n    GROUP BY recorded_date&#13;\n    ORDER BY recorded_date ASC&#13;\n)&#13;\nSELECT&#13;\n    recorded_date,&#13;\n    SUM(total_energy) OVER (&#13;\n        ORDER BY recorded_date ASC&#13;\n    ) AS cumulative_total_energy,&#13;\n    ROUND(&#13;\n        SUM(total_energy) OVER (ORDER BY recorded_date ASC) * 100.0&#13;\n        \/ (SELECT SUM(total_energy) FROM energy_by_date),&#13;\n        0&#13;\n    ) AS percentage_of_total_energy&#13;\nFROM energy_by_date;<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Coding Resolution (1.84 ms)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>import pandas as pd&#13;\nmerged_df = pd.concat([fb_eu_energy, fb_asia_energy, fb_na_energy])&#13;\n&#13;\nenergy_by_date = (&#13;\n    merged_df.groupby('recorded_date', as_index=False)['consumption']&#13;\n    .sum()&#13;\n    .sort_values('recorded_date')&#13;\n)&#13;\n&#13;\nenergy_by_date['cumulative_total_energy'] = energy_by_date['consumption'].cumsum()&#13;\nenergy_by_date['percentage_of_total_energy'] = spherical(&#13;\n    energy_by_date['cumulative_total_energy'] * 100 \/ energy_by_date['consumption'].sum()&#13;\n)&#13;\n&#13;\nenergy_by_date['recorded_date'] = pd.to_datetime(&#13;\n    energy_by_date['recorded_date']&#13;\n).dt.strftime('%Y-%m-%d')&#13;\n&#13;\noutcome = energy_by_date[&#13;\n    ['recorded_date', 'cumulative_total_energy', 'percentage_of_total_energy']&#13;\n]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Agent Immediate<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>Tables:&#13;\n- fb_eu_energy   (recorded_date TEXT, consumption INTEGER)&#13;\n- fb_na_energy   (recorded_date TEXT, consumption INTEGER)&#13;\n- fb_asia_energy (recorded_date TEXT, consumption INTEGER)&#13;\nQuery: Mix all three tables. Sum consumption by date. Output:&#13;\n- recorded_date&#13;\n- cumulative_total_energy (working sum throughout dates, ordered by date)&#13;\n- percentage_of_total_energy (working cumulative \/ grand complete * 100,&#13;\n  rounded to the closest complete quantity)<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Agent Output (4 s)<\/h4>\n<div style=\"width: 98%; overflow: auto; padding-left: 10px; padding-bottom: 10px; padding-top: 10px; background: #F5F5F5;\">\n<pre><code>WITH all_energy AS (&#13;\n    SELECT recorded_date, consumption FROM fb_eu_energy&#13;\n    UNION ALL&#13;\n    SELECT recorded_date, consumption FROM fb_na_energy&#13;\n    UNION ALL&#13;\n    SELECT recorded_date, consumption FROM fb_asia_energy&#13;\n),&#13;\ndaily_totals AS (&#13;\n    SELECT recorded_date, SUM(consumption) AS daily_total&#13;\n    FROM all_energy&#13;\n    GROUP BY recorded_date&#13;\n)&#13;\nSELECT&#13;\n    recorded_date,&#13;\n    SUM(daily_total) OVER (ORDER BY recorded_date) AS cumulative_total_energy,&#13;\n    ROUND(&#13;\n        SUM(daily_total) OVER (ORDER BY recorded_date) * 100.0&#13;\n        \/ SUM(daily_total) OVER (),&#13;\n        0&#13;\n    ) AS percentage_of_total_energy&#13;\nFROM daily_totals&#13;\nORDER BY recorded_date;<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Output: All three return the identical desk.<\/p>\n<p>\u00a0<\/p>\n<table style=\"width: 100%; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; color: #333;\">\n<thead>\n<tr style=\"background-color: #ffd29a;\">\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">recorded_date<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">cumulative_total_energy<\/th>\n<th style=\"padding: 12px; border: 1px solid #ddd; text-align: left;\">percentage_of_total_energy<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-01<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">1050<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">13<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-02<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2175<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">27<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-03<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">3275<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">40<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-04<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">4450<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">55<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-05<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">5650<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">69<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-06<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">6900<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">85<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">2020-01-07<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">8150<\/td>\n<td style=\"padding: 12px; border: 1px solid #ddd;\">100<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p>The agent used <code>SUM(daily_total) OVER ()<\/code> (a window perform with no <code>ORDER BY<\/code>) because the denominator slightly than the scalar subquery within the SQL reference resolution. Each approaches are legitimate. The output matched precisely.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>How the Three Evaluate<\/h2>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"SQL vs Pandas vs AI Agents\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi_sql-vs-pandas-vs-ai-agents-4.png\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pace<\/h4>\n<p>At this information scale, SQL ran in 0.002-0.010 ms, Pandas in 0.4-2.1 ms. The agent added 2-4 seconds of huge language mannequin (LLM) inference time earlier than any SQL ran.<\/p>\n<p>The agent generates code first; that era time is the end-to-end latency for every question cycle. At warehouse scale, the hole closes to close zero as soon as code is generated; SQL positive aspects additional as a result of it runs contained in the database engine, and Pandas hits a reminiscence ceiling round 10 million rows and desires <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/spark.apache.org\/\" target=\"_blank\">Apache Spark<\/a><\/strong> or <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/pola.rs\/\" target=\"_blank\">Polars<\/a><\/strong> past that.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Accuracy and Hallucination Danger<\/h4>\n<p>SQL and Pandas are deterministic. The identical code on the identical information offers the identical reply each time. With schema-grounded prompts, Claude received all three questions proper, however every name produced totally different SQL (totally different frequent desk expression (CTE) names, totally different column aliases, totally different however equal approaches). With out the schema, hallucination danger climbs quick.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Explainability and Debugging<\/h4>\n<p>A SQL question reads in a single block. A foul be a part of situation is seen proper within the textual content. Pandas wants Python fluency, however you&#8217;ll be able to examine the <code>DataFrame<\/code> at every step. Brokers clarify their reasoning in English, then produce code that you could be or will not be proven. If the generated SQL is flawed, you are tracing an error by means of a mannequin&#8217;s reasoning chain slightly than studying a question you wrote.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Flexibility and Manufacturing Readiness<\/h4>\n<p>Pandas is the clearest choice for customized transformations, string parsing, and iterative characteristic engineering. SQL handles set logic cleanly and will get verbose for procedural work. Brokers reply plain-English requests properly, with the least consistency when schemas are complicated or ambiguous. For delivery, SQL is probably the most confirmed choice in analytics; Pandas is reliable with exams; and brokers are reliable at the moment for low-stakes queries or when the output is reviewed earlier than it runs.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>What the Agent Outcomes Truly Present<\/h2>\n<p>\u00a0<br \/>With a schema-grounded immediate, Claude received all three appropriate: Straightforward, Medium, and Exhausting. The agent&#8217;s SQL for the Exhausting query used a special window perform sample than the reference resolution and nonetheless returned the right desk.<\/p>\n<p>Two issues restrict that discovering. First, reproducibility: every API name can return totally different SQL for a similar query. The logic is equal, however a workforce reviewing agent-generated queries must confirm the outputs slightly than belief that at the moment&#8217;s appropriate run will match tomorrow&#8217;s. Second, schema dependency: the prompts above embody desk and column names, in addition to pattern rows. Take away these, and the agent guesses.<\/p>\n<p>At Straightforward issue, a flawed guess produces an empty outcome. At Exhausting issue, a flawed guess produces a believable flawed outcome with no error.<\/p>\n<p>The sensible sample is: present the complete schema, ask for SQL, then run and confirm the output earlier than it goes downstream.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Conclusion<\/h2>\n<p>\u00a0<br \/>SQL, Pandas, and Claude every received the identical three analytics questions proper when used appropriately. The variations are in pace (0.01 ms vs 4 seconds), reproducibility, and what occurs if you scale back the context.<\/p>\n<p>SQL matches structured retrieval and set-based logic with millisecond execution and deterministic output. Pandas matches customized transformations and step-by-step pocket book work as much as about 10 million rows. The agent matches first-draft queries and advert hoc exploration, with the complete schema within the immediate and a human reviewing the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"SQL vs Pandas vs AI Agents\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi_sql-vs-pandas-vs-ai-agents-5.png\"\/><br \/>\u00a0<\/p>\n<p>The agent received the Exhausting query proper through the use of <code>SUM() OVER()<\/code> as a substitute of a scalar subquery, which is a sound strategy that SQL&#8217;s reference resolution did not take. That is the sincere model of this comparability: the agent can generate appropriate, inventive SQL. It simply provides latency, varies between runs, and relies upon solely on what you place within the immediate.<br \/>\u00a0<br \/>\u00a0<\/p>\n<p><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/twitter.com\/StrataScratch\" rel=\"noopener\"><b><strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/twitter.com\/StrataScratch\" target=\"_blank\" rel=\"noopener noreferrer\">Nate Rosidi<\/a><\/strong><\/b><\/a> is an information scientist and in product technique. He is additionally an adjunct professor instructing analytics, and is the founding father of StrataScratch, a platform serving to information scientists put together for his or her interviews with actual interview questions from prime firms. Nate writes on the most recent developments within the profession market, offers interview recommendation, shares information science initiatives, and covers every part SQL.<\/p>\n<\/p><\/div>\n<p><template id="LdNeaTJHNX2frFDCE3qK"></template><\/script><br \/>\n<br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 #\u00a0Introduction \u00a0We gave the identical three interview questions from StrataScratch to SQL, Pandas, and a Claude agent. Each piece of code executed towards the identical dataset, and each timing quantity is a median over 500 runs. The agent&#8217;s solutions are precisely what Claude generated in response to a documented immediate, as a substitute of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":16505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[617,1856,3666,1367,9290,1808],"class_list":["post-16503","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-agents","tag-analytics","tag-pandas","tag-problems","tag-solves","tag-sql"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/16503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16503"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/16503\/revisions"}],"predecessor-version":[{"id":16504,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/16503\/revisions\/16504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/16505"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- This website is optimized by Airlift. Learn more: https://airlift.net. Template:. Learn more: https://airlift.net. Template: 69d9690a190636c2e0989534. Config Timestamp: 2026-04-10 21:18:02 UTC, Cached Timestamp: 2026-07-08 14:23:53 UTC -->