https://github.com/pola-rs/polars#handles-larger-than-ram-da...
DuckDB produces Pandas dataframes, so you would just do df.T. No need to choose between one the other.
But to answer your original question, the SQL analogue to a transpose are PIVOT/UNPIVOT operations which are mathematically rotation operations on invariants (your dimensions). This makes them much more general than a transpose -- which are just rotation operations on the rows/cols. PIVOT/UNPIVOT work on non-square data and allow you to specify different types of aggregations. PIVOT/UNPIVOT keywords are not yet implemented in DuckDB but are on the roadmap if I'm not mistaken.
Transforming into a pandas df isn't zero copy.
UNPIVOT and PIVOT are quite verbose compared to df.T.
In pandas it’s:
prices_df.loc['2020'] += 1
If you had a temperature forecast and you wanted to add the expected temperature miss to them, how would you do that on sql?In pandas it’s:
temps_df + expected_miss_dfFor example, this is how some basic operations would look in pandas.
Bump prices in 2020 up $1:
prices_df.loc['2020'] += 1
Add expected temperature offsets to base temperature forecast: temp_df + offset_df
Now imagine thousands of such operations, and you can see the necessity of pandas in models like this.How big can you go, and how does speed compare to Spark? (I'm guessing significantly faster from my experience using Duckdb on smaller machines)
Mixed experience, would definitely not put it in a system that isn’t ok crashing frequently.
It segfaults on Alpine (argh, C++!), and force exits the whole NodeJS process when it gets unexpected HTTP responses from S3.
In an archive run of 2M pushes it’ll crash the process 4-5 times.
Overall still really, really like it, but learned to not trust it
If I never have to write ETL pipelines again, I won't be upset about it.
Because it’s a single machine (no distributed cluster) DuckDB can heavily parallelize and vectorize. I don’t know if I can give you perf numbers but complex analytic queries over the entire dataset regularly finish in 1-2 mins (not scientific since I’m not telling what kinds of queries I’m running).
I’ve used Spark SQL and DuckDB overall is just more ergonomic, less boilerplate and is much faster since it is so lightweight.
Granted DuckDB can only process data on one machine (whereas Spark can scale up indefinitely by adding machines) but most data sets I work with fit on a single beefy machine.
Distributed computing — most of the time, you ain’t gonna need it.
It’s like StackOverflow: it serves 2B requests a month but only runs on a few on-prem servers. Most people think this is impossible but you can actually do a lot with very few machines if you’re smart about it. Same with data. Big data is overrated.
There was no cluster to set up or administer using DuckDB.
If you have genuinely big and unstructured data then of course you need a cluster and would reach for Spark.
If you have smallish data then maybe DuckDB has a role because working with SQL is nicer than Pandas. But a lot of time you actually need the complexity of Pandas to do the transformation you need.
DuckDB is neat but I still can’t quite convince myself of a killer use case.
Really? I prefer working with dataframe apis. You get a nice sql-like paradigm plus all the control structures of the runtime.
Also Pandas methods are imperative so cannot be optimized. SQL is declarative so it can be optimized to the hilt and DuckDB is faster than Pandas in almost all cases, even on Pandas data frames themselves! (partly due to vectorization).
If you have a few billion records and you want to filter, join, aggregate them using SQL then DBT against an OLAP server solves that issue so well that it doesn’t leave much white space for DuckDB.
I mentioned modern data stack because when you have SaaS, low code, consumption based billing, open source etc then it treads even more on the DuckDB value prop.
Ninja edit before anyone misconstrues this. I am not saying that the typical desktop has these specs. I am saying that the class of hardware that is most commonly run on desktops includes SKUs that can meet this spec. Desktop-class means the same motherboard socket and processor architecture.
https://pedram.substack.com/p/streaming-data-pipelines-with-...
I have successfully used DuckDB like above for preparing an ML dataset from about 100GB of input.
DuckDB is undergoing rapid development these days. There have been format-breaking changes and bugs that could lose data. I would not yet trust DuckDB for long-term storage or archival purposes. Parquet is a better choice for that.