Skip to content

Instantly share code, notes, and snippets.

@SimonAB
Last active February 20, 2020 23:02
Show Gist options
  • Save SimonAB/1a840a34333aa991288782047984f743 to your computer and use it in GitHub Desktop.
Save SimonAB/1a840a34333aa991288782047984f743 to your computer and use it in GitHub Desktop.
"""
This function takes a dataframe and a column name (as symbol), and
prints out the count and the proportion of items within that column.
"""
using DataFrames, Query
function counter(df::DataFrame, col::Symbol)
for level in unique(df[!, col])
t = df |>
@filter(_[col] == level)|>
DataFrame
len_t = length(t[!, col])
per_t = round(100*length(t[!, col])/length(df[!, col]), digits=2)
println("$level: $len_t ($per_t% of total)")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment