Down the Data Rabbit Hole: Alice's Adventure from Pandas to DuckDB Wonderland
Tags: python, pandas, duckdb, beginners
Published: 2023-11-16 20:40:15


![Alice falling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0yam0ahzhmu0gnlikiz.png)
### Prologue: Falling Down the Data Rabbit Hole


In a universe where data unfolds like a never-ending story, meet Alice, a data analyst with an adventurous spirit. One day, a flicker of curiosity leads her to an unexpected rabbit hole. With a heart full of excitement, she dives in. This is no ordinary journey: it’s Alice’s vibrant plunge from the familiar world of Pandas into the magical realm of DuckDB. Join her as she discovers Wonderland on this captivating adventure, where every discovery is a thrill and every insight a delight.

___


![tea party](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04q5vpcyjal6fsqo0j63.png)
### **Chapter 1: The Pandas Tea Party**

Alice found herself at a peculiar tea party, hosted by none other than the Mad Hatter, known to the data world as Pandas. Surrounded by stacks of CSV files, she began her usual routine:

```python
import pandas as pd
from pathlib import Path

# At the Pandas tea party, surrounded by piles of CSV files
file_list = Path("/teaparty").glob('cards*.csv')
concatenated_df = pd.concat((pd.read_csv(file) 
for file in file_list), 
ignore_index=True)

```

As she worked, concatenating file after file, Alice couldn't help but feel overwhelmed. The process was familiar but cumbersome, much like the chaotic chatter around the tea party table.
___

![chasing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxors4i6aozbalnp2o1j.png)
## **Chapter 2: Chasing the DuckDB White Rabbit**

Just then, Alice spotted a White Rabbit, darting past the tea party. This rabbit, known as DuckDB, beckoned her with the promise of a more efficient way to handle her data. Intrigued, Alice followed and discovered a world where data was not a burden but a delight:

```python
import duckdb

# Chasing the White Rabbit into a world of simpler data handling
concatenated_df = duckdb.query("""
      SELECT 
         * 
      FROM './teaparty/cards*.csv'
""").df()
```

In awe, Alice watched as multiple files blended into one with a simple query, no longer needing to juggle them manually. The White Rabbit had shown her a more elegant and less memory-intensive path.

___


![queen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjej5k6kzu3l0890iz3c.png)
## **Chapter 3: The DuckDB Wonderland of Transformations**

As Alice ventured deeper into this wonderland, she encountered the Queen of Hearts, who demanded swift and complex data transformations. In the realm of DuckDB, this was not only possible but surprisingly straightforward:

```python
transformed_df = duckdb.query("""
    SELECT
        queen,
        SUM(soldier) as total_soldiers,
        AVG(hearts) as avg_hearts
    FROM './teaparty/cards*.csv'
    GROUP BY queen
""").df()
```

With DuckDB, Alice easily satisfied the Queen's demands, performing tasks that once seemed as daunting as painting the roses red.

## **Epilogue: Awakening in a New World of Data Processing**

As Alice awoke from her journey, she found herself back in her world, but with a new perspective on data processing. The lessons from DuckDB Wonderland had transformed her approach, making her tasks more efficient and her analyses more powerful.

Join Alice in her adventure and explore the wonders of DuckDB. Let it transform your data processing tasks from a mundane chore into a magical experience, just like a day spent in Wonderland.

---

Until then, keep on coding like a Cheshire Cat.