4 ms·
How would you do df.T in sql?
by nojito 4y ago
How would you do df.T in sql?
- wenc 4y agodf.T is a special Pandas dataframe transpose on the dataframe index and the columns. 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.
- nojito 4y ago>DuckDB produces Pandas dataframes, so you would just do df.T. No need to choose between one the other. Transforming into a pandas df isn't zero copy. UNPIVOT and PIVOT are quite verbose compared to df.T.