Last active
February 20, 2020 23:02
-
-
Save SimonAB/1a840a34333aa991288782047984f743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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