{"id":7618,"date":"2025-10-12T19:59:23","date_gmt":"2025-10-12T19:59:23","guid":{"rendered":"https:\/\/techtrendfeed.com\/?p=7618"},"modified":"2025-10-12T19:59:24","modified_gmt":"2025-10-12T19:59:24","slug":"we-benchmarked-duckdb-sqlite-and-pandas-on-1m-rows-right-heres-what-occurred","status":"publish","type":"post","link":"https:\/\/techtrendfeed.com\/?p=7618","title":{"rendered":"We Benchmarked DuckDB, SQLite, and Pandas on 1M Rows: Right here\u2019s What Occurred"},"content":{"rendered":"<p> <br \/>\n<\/p>\n<div id=\"post-\">\n<p>    <center><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-1-scaled.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-1-scaled.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/><span>Picture by Creator<\/span><\/center><br \/>\n\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Introduction<\/h2>\n<p>\u00a0<br \/>There are quite a few instruments for processing datasets right now. All of them declare \u2014 after all they do \u2014 that they\u2019re one of the best and the precise alternative for you. However are they? There are two predominant necessities these instruments ought to fulfill: they need to simply carry out on a regular basis knowledge evaluation operations and achieve this rapidly, even underneath the stress of huge datasets.<\/p>\n<p>To find out one of the best software amongst <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/duckdb.org\/\" target=\"_blank\">DuckDB<\/a><\/strong>, <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/sqlite3.html\" target=\"_blank\">SQLite<\/a><\/strong>, and <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/pandas.pydata.org\/\" target=\"_blank\">Pandas<\/a><\/strong>, we examined them underneath these circumstances.<\/p>\n<p>First, we gave them solely on a regular basis analytical duties: summing values, grouping by classes, filtering with circumstances, and multi-field aggregations. This mirrored how analysts really work with actual datasets, in comparison with eventualities designed to showcase one of the best traits of a software.<\/p>\n<p>Second, we carried out these operations on a Kaggle dataset with over 1 million rows. It\u2019s a sensible tipping level \u2014 sufficiently small to run on a single machine, but giant sufficient that reminiscence stress and question pace begin to reveal clear variations between instruments.<\/p>\n<p>Let\u2019s see how these exams went.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>The Dataset We Used<\/h2>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Dataset Overview<\/h3>\n<p>We used the Financial institution dataset from <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.kaggle.com\/datasets\/ksabishek\/massive-bank-dataset-1-million-rows\" target=\"_blank\">Kaggle<\/a><\/strong>. This dataset comprises over 1 million rows, comprising 5 columns:<\/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\">Column Title<\/th>\n<th style=\"padding: 12px;border: 1px solid #ddd;text-align: left\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Date<\/td>\n<td style=\"padding: 12px;border: 1px solid #ddd\">The date the transaction occurred<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Area<\/td>\n<td style=\"padding: 12px;border: 1px solid #ddd\">The enterprise class or sort (RETAIL, RESTAURANT)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Location<\/td>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Geographic area (Goa, Mathura)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Worth<\/td>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Transaction worth<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px;border: 1px solid #ddd\">Transaction_count<\/td>\n<td style=\"padding: 12px;border: 1px solid #ddd\">The whole variety of transactions on that day<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n<p>This dataset is generated utilizing Python. Whereas it could not totally resemble real-life knowledge, its measurement and construction are enough to check and examine the efficiency variations between the instruments.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Peeking Into the Information with Pandas<\/h3>\n<p>We used <strong><a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/pandas.pydata.org\/\" target=\"_blank\">Pandas<\/a><\/strong> to load the dataset right into a Jupyter pocket book and look at its normal construction, dimensions, and null values. Right here is the code.<\/p>\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;\ndf = pd.read_excel('bankdataset.xlsx')&#13;\n&#13;\nprint(\"Dataset form:\", df.form)&#13;\n&#13;\ndf.head()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-3.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-3.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>In order for you a fast reference to widespread operations when exploring datasets, take a look at this helpful <a rel=\"nofollow\" target=\"_blank\" href=\"https:\/\/www.stratascratch.com\/blog\/the-pandas-cheat-sheet-to-be-a-better-data-scientist\/?utm_source=blog&amp;utm_medium=click&amp;utm_campaign=kdn+benchmarked+duckdb+sqlite+pandas\" target=\"_blank\">Pandas Cheat Sheet<\/a>.<\/p>\n<p>Earlier than benchmarking, let\u2019s see  arrange the setting.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Setting Up a Truthful Testing Setting<\/h2>\n<p>\u00a0<br \/>All three instruments \u2014 DuckDB, SQLite, and Pandas \u2014 had been arrange and run in the identical Jupyter Pocket book setting to make sure the check was honest. This ensured that the circumstances throughout runtime and the usage of reminiscence remained fixed all through.<\/p>\n<p>First, we put in and loaded the mandatory packages.<\/p>\n<p>Listed below are the instruments we wanted:<\/p>\n<ul>\n<li>pandas: for traditional <code>DataFrame<\/code> operations\n<\/li>\n<li>duckdb: for SQL execution on a <code>DataFrame<\/code>\n<\/li>\n<li>sqlite3: for managing an embedded SQL database\n<\/li>\n<li>time: for capturing execution time\n<\/li>\n<li>memory_profiler: to measure reminiscence allocation\n<\/li>\n<\/ul>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code># Set up if any of them are usually not in your setting&#13;\n!pip set up duckdb --quiet&#13;\n&#13;\nimport pandas as pd&#13;\nimport duckdb&#13;\nimport sqlite3&#13;\nimport time&#13;\nfrom memory_profiler import memory_usage<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Now let\u2019s put together the info in a format that may be shared throughout all three instruments.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Loading Information into Pandas<\/h3>\n<p>We&#8217;ll use Pandas to load the dataset as soon as, after which we\u2019ll share or register it for DuckDB and SQLite.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>df = pd.read_excel('bankdataset.xlsx')&#13;\n&#13;\ndf.head()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output to validate.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-4.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-4.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Registering Information with DuckDB<\/h3>\n<p>DuckDB allows you to straight entry Pandas <code>DataFrame<\/code>s. You do not have to transform something\u2014simply register and question. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code># Register DataFrame as a DuckDB desk&#13;\nduckdb.register(\"bank_data\", df)&#13;\n&#13;\n# Question through DuckDB&#13;\nduckdb.question(\"SELECT * FROM bank_data LIMIT 5\").to_df()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-5.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-5.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Making ready Information for SQLite<\/h3>\n<p>Since SQLite would not learn Excel recordsdata straight, we began by including the Pandas <code>DataFrame<\/code> to an in-memory database. After that, we used a easy question to look at the info format.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>conn_sqlite = sqlite3.join(\":reminiscence:\")&#13;\n&#13;\ndf.to_sql(\"bank_data\", conn_sqlite, index=False, if_exists=\"change\")&#13;\n&#13;\npd.read_sql_query(\"SELECT * FROM bank_data LIMIT 5\", conn_sqlite)<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-6.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-6.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>How We Benchmarked the Instruments<\/h2>\n<p>\u00a0<br \/>We used the identical 4 queries on DuckDB, SQLite, and Pandas to check their efficiency. Every question was designed to handle a standard analytical job that mirrors how knowledge evaluation is utilized in the true world.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Making certain Constant Setup<\/h3>\n<p>The in-memory dataset was utilized by all three instruments.<\/p>\n<ul>\n<li>Pandas queried the <code>DataFrame<\/code> straight\n<\/li>\n<li>DuckDB executed SQL queries straight towards the <code>DataFrame<\/code>\n<\/li>\n<li>SQLite saved a duplicate of the <code>DataFrame<\/code> in an in-memory database and ran SQL queries on it\n<\/li>\n<\/ul>\n<p>This technique ensured that every one three instruments used the identical knowledge and operated with the identical system settings.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Measuring Execution Time<\/h3>\n<p>To trace question length, Python\u2019s <code>time<\/code> module wrapped every question in a easy begin\/finish timer. Solely the question execution time was recorded; data-loading and preparation steps had been excluded.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Monitoring Reminiscence Utilization<\/h3>\n<p>Together with processing time, reminiscence utilization signifies how nicely every engine performs with giant datasets.<\/p>\n<p>If desired, reminiscence utilization could be sampled instantly earlier than and after every question to estimate incremental RAM consumption.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>The Benchmark Queries<\/h3>\n<p>We examined every engine on the identical 4 on a regular basis analytical duties:<\/p>\n<ol>\n<li>Whole transaction worth: summing a numeric column\n<\/li>\n<li>Group by area: aggregating transaction counts per class\n<\/li>\n<li>Filter by location: filtering rows by a situation earlier than aggregation\n<\/li>\n<li>Group by area &amp; location: multi-field aggregation with averages\n<\/li>\n<\/ol>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Benchmark Outcomes<\/h2>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Question 1: Whole Transaction Worth<\/h3>\n<p>Right here we measure how Pandas, DuckDB, and SQLite carry out when summing the <code>Worth<\/code> column throughout the dataset.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Efficiency<\/h4>\n<p>We calculate the entire transaction worth utilizing <code>.sum()<\/code> on the <code>Worth<\/code> column. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>pandas_results = []&#13;\n&#13;\ndef pandas_q1():&#13;\n    return df['Value'].sum()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\npandas_q1()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\npandas_results.append({&#13;\n    \"engine\": \"Pandas\",&#13;\n    \"question\": \"Whole transaction worth\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\npandas_results<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-7.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-7.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>DuckDB Efficiency<\/h4>\n<p>We calculate the entire transaction worth utilizing a full-column aggregation. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>duckdb_results = []&#13;\n&#13;\ndef duckdb_q1():&#13;\n    return duckdb.question(\"SELECT SUM(worth) FROM bank_data\").to_df()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nduckdb_q1()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nduckdb_results.append({&#13;\n    \"engine\": \"DuckDB\",&#13;\n    \"question\": \"Whole transaction worth\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\nduckdb_results<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-8.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-8.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQLite Efficiency<\/h4>\n<p>We calculate the entire transaction worth by summing the <code>worth<\/code> column. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>sqlite_results = []&#13;\n&#13;\ndef sqlite_q1():&#13;\n    return pd.read_sql_query(\"SELECT SUM(worth) FROM bank_data\", conn_sqlite)&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nsqlite_q1()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nsqlite_results.append({&#13;\n    \"engine\": \"SQLite\",&#13;\n    \"question\": \"Whole transaction worth\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\nsqlite_results<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-9.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-9.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Total Efficiency Evaluation<\/h4>\n<p>Now let\u2019s examine execution time and reminiscence utilization. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>import matplotlib.pyplot as plt&#13;\n&#13;\n&#13;\nall_q1 = pd.DataFrame(pandas_results + duckdb_results + sqlite_results)&#13;\n&#13;\nfig, axes = plt.subplots(1, 2, figsize=(10,4))&#13;\n&#13;\nall_q1.plot(x=\"engine\", y=\"time\", sort=\"barh\", ax=axes[0], legend=False, title=\"Execution Time (s)\")&#13;\nall_q1.plot(x=\"engine\", y=\"reminiscence\", sort=\"barh\", colour=\"salmon\", ax=axes[1], legend=False, title=\"Reminiscence Utilization (MB)\")&#13;\n&#13;\nplt.tight_layout()&#13;\nplt.present()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-10.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-10.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>Pandas is by far the quickest and most memory-efficient right here, finishing nearly immediately with minimal RAM utilization. DuckDB is barely slower and makes use of extra reminiscence however stays environment friendly, whereas SQLite is each the slowest and the heaviest by way of reminiscence consumption.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Question 2: Group by Area<\/h3>\n<p>Right here we measure how Pandas, DuckDB, and SQLite carry out when grouping transactions by <code>Area<\/code> and summing their counts.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Efficiency<\/h4>\n<p>We calculate the entire transaction rely per area utilizing <code>.groupby()<\/code> on the <code>Area<\/code> column.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def pandas_q2():&#13;\n    return df.groupby('Area')['Transaction_count'].sum()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\npandas_q2()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\npandas_results.append({&#13;\n    \"engine\": \"Pandas\",&#13;\n    \"question\": \"Group by area\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n[p for p in pandas_results if p[\"query\"] == \"Group by area\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-11.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-11.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>DuckDB Efficiency<\/h4>\n<p>We calculate the entire transaction rely per area utilizing a SQL <code>GROUP BY<\/code> on the <code>area<\/code> column.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def duckdb_q2():&#13;\n    return duckdb.question(\"\"\"&#13;\n        SELECT area, SUM(transaction_count) &#13;\n        FROM bank_data &#13;\n        GROUP BY area&#13;\n    \"\"\").to_df()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nduckdb_q2()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nduckdb_results.append({&#13;\n    \"engine\": \"DuckDB\",&#13;\n    \"question\": \"Group by area\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in duckdb_results if p[\"query\"] == \"Group by area\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-12.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-12.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQLite Efficiency<\/h4>\n<p>We calculate the entire transaction rely per area utilizing SQL <code>GROUP BY<\/code> on the in-memory desk.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def sqlite_q2():&#13;\n    return pd.read_sql_query(\"\"\"&#13;\n        SELECT area, SUM(transaction_count) AS total_txn&#13;\n        FROM bank_data&#13;\n        GROUP BY area&#13;\n    \"\"\", conn_sqlite)&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nsqlite_q2()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nsqlite_results.append({&#13;\n    \"engine\": \"SQLite\",&#13;\n    \"question\": \"Group by area\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in sqlite_results if p[\"query\"] == \"Group by area\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-13.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-13.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Total Efficiency Evaluation<\/h4>\n<p>Now let\u2019s examine execution time and reminiscence utilization. Right here is the code.<\/p>\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;\nimport matplotlib.pyplot as plt&#13;\n&#13;\ngroupby_results = [r for r in (pandas_results + duckdb_results + sqlite_results) &#13;\n                   if \"Group by\" in r[\"query\"]]&#13;\n&#13;\ndf_groupby = pd.DataFrame(groupby_results)&#13;\n&#13;\nfig, axes = plt.subplots(1, 2, figsize=(10,4))&#13;\n&#13;\ndf_groupby.plot(x=\"engine\", y=\"time\", sort=\"barh\", ax=axes[0], legend=False, title=\"Execution Time (s)\")&#13;\ndf_groupby.plot(x=\"engine\", y=\"reminiscence\", sort=\"barh\", colour=\"salmon\", ax=axes[1], legend=False, title=\"Reminiscence Utilization (MB)\")&#13;\n&#13;\nplt.tight_layout()&#13;\nplt.present()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-14.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-14.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>DuckDB is quickest, Pandas trades a bit extra time for decrease reminiscence, whereas SQLite is each slowest and most memory-hungry.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Question 3: Filter by Location (Goa)<\/h3>\n<p>Right here we measure how Pandas, DuckDB, and SQLite carry out when filtering the dataset for <code>Location = 'Goa'<\/code> and summing the transaction values.<\/p>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Efficiency<\/h4>\n<p>We filter rows for <code>Location == 'Goa'<\/code> and sum their values. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def pandas_q3():&#13;\n    return df[df['Location'] == 'Goa']['Value'].sum()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\npandas_q3()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\npandas_results.append({&#13;\n    \"engine\": \"Pandas\",&#13;\n    \"question\": \"Filter by location\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in pandas_results if p[\"query\"] == \"Filter by location\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-15.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-15.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>DuckDB Efficiency<\/h4>\n<p>We filter transactions for <code>Location = 'Goa'<\/code> and calculate their whole worth. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def duckdb_q3():&#13;\n    return duckdb.question(\"\"\"&#13;\n        SELECT SUM(worth) &#13;\n        FROM bank_data &#13;\n        WHERE location = 'Goa'&#13;\n    \"\"\").to_df()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nduckdb_q3()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nduckdb_results.append({&#13;\n    \"engine\": \"DuckDB\",&#13;\n    \"question\": \"Filter by location\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in duckdb_results if p[\"query\"] == \"Filter by location\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-16.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-16.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQLite Efficiency<\/h4>\n<p>We filter transactions for <code>Location = 'Goa'<\/code> and sum their values. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def sqlite_q3():&#13;\n    return pd.read_sql_query(\"\"\"&#13;\n        SELECT SUM(worth) AS total_value&#13;\n        FROM bank_data&#13;\n        WHERE location = 'Goa'&#13;\n    \"\"\", conn_sqlite)&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nsqlite_q3()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nsqlite_results.append({&#13;\n    \"engine\": \"SQLite\",&#13;\n    \"question\": \"Filter by location\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in sqlite_results if p[\"query\"] == \"Filter by location\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-17.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-17.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Total Efficiency Evaluation<\/h4>\n<p>Now let\u2019s examine execution time and reminiscence utilization. Right here is the code.<\/p>\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;\nimport matplotlib.pyplot as plt&#13;\n&#13;\nfilter_results = [r for r in (pandas_results + duckdb_results + sqlite_results)&#13;\n                  if r[\"query\"] == \"Filter by location\"]&#13;\n&#13;\ndf_filter = pd.DataFrame(filter_results)&#13;\n&#13;\nfig, axes = plt.subplots(1, 2, figsize=(10, 4))&#13;\n&#13;\ndf_filter.plot(x=\"engine\", y=\"time\", sort=\"barh\", ax=axes[0], legend=False, title=\"Execution Time (s)\")&#13;\ndf_filter.plot(x=\"engine\", y=\"reminiscence\", sort=\"barh\", colour=\"salmon\", ax=axes[1], legend=False, title=\"Reminiscence Utilization (MB)\")&#13;\n&#13;\nplt.tight_layout()&#13;\nplt.present()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-18.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-18.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>DuckDB is the quickest and best; Pandas is slower with larger reminiscence utilization; and SQLite is the slowest however lighter on reminiscence.<\/p>\n<p>\u00a0<\/p>\n<h3><span>\/\/\u00a0<\/span>Question 4: Group by Area &amp; Location<\/h3>\n<p>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Pandas Efficiency<\/h4>\n<p>We calculate the common transaction worth grouped by each <code>Area<\/code> and <code>Location<\/code>. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def pandas_q4():&#13;\n    return df.groupby(['Domain', 'Location'])['Value'].imply()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\npandas_q4()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\npandas_results.append({&#13;\n    \"engine\": \"Pandas\",&#13;\n    \"question\": \"Group by area &amp; location\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in pandas_results if p[\"query\"] == \"Group by area &amp; location\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-19.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-19.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>DuckDB Efficiency<\/h4>\n<p>We calculate the common transaction worth grouped by each <code>area<\/code> and <code>location<\/code>. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def duckdb_q4():&#13;\n    return duckdb.question(\"\"\"&#13;\n        SELECT area, location, AVG(worth) AS avg_value&#13;\n        FROM bank_data&#13;\n        GROUP BY area, location&#13;\n    \"\"\").to_df()&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nduckdb_q4()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nduckdb_results.append({&#13;\n    \"engine\": \"DuckDB\",&#13;\n    \"question\": \"Group by area &amp; location\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in duckdb_results if p[\"query\"] == \"Group by area &amp; location\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-20.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-20.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>SQLite Efficiency<\/h4>\n<p>We calculate the common transaction worth grouped by each <code>area<\/code> and <code>location<\/code>. Right here is the code.<\/p>\n<div style=\"width: 98%;overflow: auto;padding-left: 10px;padding-bottom: 10px;padding-top: 10px;background: #F5F5F5\">\n<pre><code>def sqlite_q4():&#13;\n    return pd.read_sql_query(\"\"\"&#13;\n        SELECT area, location, AVG(worth) AS avg_value&#13;\n        FROM bank_data&#13;\n        GROUP BY area, location&#13;\n    \"\"\", conn_sqlite)&#13;\n&#13;\nmem_before = memory_usage(-1)[0]&#13;\nbegin = time.time()&#13;\nsqlite_q4()&#13;\nfinish = time.time()&#13;\nmem_after = memory_usage(-1)[0]&#13;\n&#13;\nsqlite_results.append({&#13;\n    \"engine\": \"SQLite\",&#13;\n    \"question\": \"Group by area &amp; location\",&#13;\n    \"time\": spherical(finish - begin, 4),&#13;\n    \"reminiscence\": spherical(mem_after - mem_before, 4)&#13;\n})&#13;\n&#13;\n[p for p in sqlite_results if p[\"query\"] == \"Group by area &amp; location\"]<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-21.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-21.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<h4><span>\/\/\u00a0<\/span>Total Efficiency Evaluation<\/h4>\n<p>Now let\u2019s examine execution time and reminiscence utilization. Right here is the code.<\/p>\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;\nimport matplotlib.pyplot as plt&#13;\n&#13;\ngdl_results = [r for r in (pandas_results + duckdb_results + sqlite_results)&#13;\n               if r[\"query\"] == \"Group by area &amp; location\"]&#13;\n&#13;\ndf_gdl = pd.DataFrame(gdl_results)&#13;\n&#13;\nfig, axes = plt.subplots(1, 2, figsize=(10, 4))&#13;\n&#13;\ndf_gdl.plot(x=\"engine\", y=\"time\", sort=\"barh\", ax=axes[0], legend=False,&#13;\n            title=\"Execution Time (s)\")&#13;\ndf_gdl.plot(x=\"engine\", y=\"reminiscence\", sort=\"barh\", ax=axes[1], legend=False,&#13;\n            title=\"Reminiscence Utilization (MB)\", colour=\"salmon\")&#13;\n&#13;\nplt.tight_layout()&#13;\nplt.present()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-22.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-22.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>DuckDB handles multi-field group-bys quickest with reasonable reminiscence use, Pandas is slower with very excessive reminiscence utilization, and SQLite is the slowest with substantial reminiscence consumption.<\/p>\n<p>\u00a0<\/p>\n<h2><span>#\u00a0<\/span>Ultimate Comparability Throughout All Queries<\/h2>\n<p>\u00a0<br \/>We\u2019ve in contrast these three engines towards one another by way of reminiscence and pace. Let\u2019s test the execution time as soon as once more. Right here is the code.<\/p>\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;\nimport matplotlib.pyplot as plt&#13;\n&#13;\nall_results = pd.DataFrame(pandas_results + duckdb_results + sqlite_results)&#13;\n&#13;\nmeasure_order = [&#13;\n    \"Total transaction value\",&#13;\n    \"Group by domain\",&#13;\n    \"Filter by location\",&#13;\n    \"Group by domain &amp; location\",&#13;\n]&#13;\nengine_colors = {\"Pandas\": \"#1f77b4\", \"DuckDB\": \"#ff7f0e\", \"SQLite\": \"#2ca02c\"}&#13;\n&#13;\nfig, axes = plt.subplots(2, 2, figsize=(12, 8))&#13;\naxes = axes.ravel()&#13;\n&#13;\nfor i, q in enumerate(measure_order):&#13;\n    d = all_results[all_results[\"query\"] == q]&#13;\n    axes[i].barh(d[\"engine\"], d[\"time\"], &#13;\n                 colour=[engine_colors[e] for e in d[\"engine\"]])&#13;\n    for y, v in enumerate(d[\"time\"]):&#13;\n        axes[i].textual content(v, y, f\" {v:.3f}\", va=\"middle\")&#13;\n    axes[i].set_title(q, fontsize=10)&#13;\n    axes[i].set_xlabel(\"Seconds\")&#13;\n&#13;\nfig.suptitle(\"Per-Measure Comparability \u2014 Execution Time\", fontsize=14)&#13;\nplt.tight_layout()&#13;\nplt.present()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-23.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-23.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>This chart exhibits that DuckDB constantly maintains the bottom execution instances for nearly all queries, aside from the entire transaction worth the place Pandas edges it out; SQLite is the slowest by a large margin throughout the board. Let\u2019s test reminiscence subsequent. Right here is the code.<\/p>\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;\nimport matplotlib.pyplot as plt&#13;\n&#13;\nall_results = pd.DataFrame(pandas_results + duckdb_results + sqlite_results)&#13;\n&#13;\nmeasure_order = [&#13;\n    \"Total transaction value\",&#13;\n    \"Group by domain\",&#13;\n    \"Filter by location\",&#13;\n    \"Group by domain &amp; location\",&#13;\n]&#13;\nengine_colors = {\"Pandas\": \"#1f77b4\", \"DuckDB\": \"#ff7f0e\", \"SQLite\": \"#2ca02c\"}&#13;\n&#13;\nfig, axes = plt.subplots(2, 2, figsize=(12, 8))&#13;\naxes = axes.ravel()&#13;\n&#13;\nfor i, q in enumerate(measure_order):&#13;\n    d = all_results[all_results[\"query\"] == q]&#13;\n    axes[i].barh(d[\"engine\"], d[\"memory\"], &#13;\n                 colour=[engine_colors[e] for e in d[\"engine\"]])&#13;\n    for y, v in enumerate(d[\"memory\"]):&#13;\n        axes[i].textual content(v, y, f\" {v:.1f}\", va=\"middle\")&#13;\n    axes[i].set_title(q, fontsize=10)&#13;\n    axes[i].set_xlabel(\"MB\")&#13;\n&#13;\nfig.suptitle(\"Per-Measure Comparability \u2014 Reminiscence Utilization\", fontsize=14)&#13;\nplt.tight_layout()&#13;\nplt.present()<\/code><\/pre>\n<\/div>\n<p>\u00a0<\/p>\n<p>Right here is the output.<\/p>\n<p>\u00a0<br \/><img decoding=\"async\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\" class=\"perfmatters-lazy\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-24.png\"\/><img decoding=\"async\" src=\"https:\/\/www.kdnuggets.com\/wp-content\/uploads\/Rosidi-We-Benchmarked-DuckDB-SQLite-Pandas-24.png\" alt=\"DuckDB vs SQLite vs Pandas\" width=\"100%\"\/><br \/>\u00a0<\/p>\n<p>This chart exhibits that SQLite swings between being one of the best and the worst in reminiscence utilization, Pandas is excessive with two finest and two worst instances, whereas DuckDB stays constantly within the center throughout all queries. In consequence, DuckDB proves to be essentially the most balanced alternative total, delivering constantly quick efficiency with reasonable reminiscence utilization. Pandas exhibits extremes\u2014typically the quickest, typically the heaviest\u2014whereas SQLite struggles with pace and infrequently finally ends up on the inefficient facet for reminiscence.<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 knowledge scientists put together for his or her interviews with actual interview questions from prime corporations. Nate writes on the newest developments within the profession market, offers interview recommendation, shares knowledge science initiatives, and covers every part SQL.<\/p>\n<\/p><\/div>\n<p><template id="TTZbc4rMhRi6xha3DNYK"></template><\/script><br \/>\n<br \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Picture by Creator \u00a0 #\u00a0Introduction \u00a0There are quite a few instruments for processing datasets right now. All of them declare \u2014 after all they do \u2014 that they\u2019re one of the best and the precise alternative for you. However are they? There are two predominant necessities these instruments ought to fulfill: they need to simply [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":7620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[5865,5866,5868,648,3666,5867,1806],"class_list":["post-7618","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-benchmarked","tag-duckdb","tag-happened","tag-heres","tag-pandas","tag-rows","tag-sqlite"],"_links":{"self":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/7618","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=7618"}],"version-history":[{"count":1,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/7618\/revisions"}],"predecessor-version":[{"id":7619,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/posts\/7618\/revisions\/7619"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=\/wp\/v2\/media\/7620"}],"wp:attachment":[{"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtrendfeed.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7618"}],"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-08-11 09:47:22 UTC -->