https://github.com/pola-rs/polars#handles-larger-than-ram-da...
import duckdb as db
import pandas as pd
df = pd.read_excel(“z.xlsx”)
df2 = db.query(“select * from df join ‘s3://bucket/a.parquet’ b on df.col b.col”).df()
df3 = df2.col.apply(lambda x: x)
DuckDB can refer any Pandas data frame in the namespace as a SQL object. You can query across Parquet, CSV and Pandas data frames seamlessly.Need to join Excel with Parquet with CSV? No problem. You can do it all within DuckDB.
For 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.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_df