A spreadsheet-like pivot function

Interesting. DataFrames and DataTables do not support multiple column indices on purpose. This feature isn’t generally supported by database-like structures (AFAIK Pandas is an exception). If you need these, maybe you shouldn’t store the result in a DataFrame but in a different structure like a NamedArray an AxisArray or an IndexedTable. With a DataFrame, you would need one row for each combination of indices, with one column for each index giving the level (this is the principle of tidy data).

Regarding the implementation, you could probably use aggregate. Also, you don’t need to call eval(op): just pass the function instead of its name, i.e. sum instead of :sum.

2 Likes