Misc Tips/Tricks
There are a few miscellaneous feautures of TidierDB that are documented on this page
using DataFrames, TidierDB
df = DataFrame(id = [string('A' + i ÷ 26, 'A' + i % 26) for i in 0:9],
groups = [i % 2 == 0 ? "aa" : "bb" for i in 1:10],
value = repeat(1:5, 2),
percent = 0.1:0.1:1.0);
db = connect(duckdb());
dfv = db_table(db, df, "dfv");
DuckDB's SUMMARIZE¤
DuckDB has a feature tosummarize tables that gives information about the table, such as mean, std, q25, q75 etc. To use this feature with TidierDB, simply call an empty @summarize
.
@chain t(dfv) @summarize() @collect
4×12 DataFrame
Row | column_name | column_type | min | max | approx_unique | avg | std | q25 | q50 | q75 | count | null_percentage |
---|---|---|---|---|---|---|---|---|---|---|---|---|
String | String | String | String | Int64 | String? | String? | String? | String? | String? | Int64 | FixedDec… | |
1 | id | VARCHAR | AA | AJ | 11 | missing | missing | missing | missing | missing | 10 | 0.0 |
2 | groups | VARCHAR | aa | bb | 2 | missing | missing | missing | missing | missing | 10 | 0.0 |
3 | value | BIGINT | 1 | 5 | 5 | 3.0 | 1.4907119849998598 | 2 | 3 | 4 | 10 | 0.0 |
4 | percent | DOUBLE | 0.1 | 1.0 | 10 | 0.55 | 0.3027650354097492 | 0.3 | 0.55 | 0.8 | 10 | 0.0 |
show_query/collect¤
If you find yourself frequently showing a query while collecting, you can define the following function
sqc(qry) = @chain t(qry) begin
@aside @show_query _
@collect()
end;
Call this function at the end of a chain similar the @show_query
or@collect
macros printed query is not seen here as it prints to the REPL
@chain t(dfv) @summarize() sqc()
4×12 DataFrame
Row | column_name | column_type | min | max | approx_unique | avg | std | q25 | q50 | q75 | count | null_percentage |
---|---|---|---|---|---|---|---|---|---|---|---|---|
String | String | String | String | Int64 | String? | String? | String? | String? | String? | Int64 | FixedDec… | |
1 | id | VARCHAR | AA | AJ | 11 | missing | missing | missing | missing | missing | 10 | 0.0 |
2 | groups | VARCHAR | aa | bb | 2 | missing | missing | missing | missing | missing | 10 | 0.0 |
3 | value | BIGINT | 1 | 5 | 5 | 3.0 | 1.4907119849998598 | 2 | 3 | 4 | 10 | 0.0 |
4 | percent | DOUBLE | 0.1 | 1.0 | 10 | 0.55 | 0.3027650354097492 | 0.3 | 0.55 | 0.8 | 10 | 0.0 |
Color Printing¤
Queries print with some code words in color to the REPL. To turn off this feature, run one of the following.
TidierDB.color[] = false
DB.color[] = false
This page was generated using Literate.jl.