Julia : count frequency of column value (unique values of non- numeric column)

Viewed 814

I am trying to find the unique values of column

countmap(df[:column_name])

but getting error

ArgumentError: syntax df[column] is not supported use df[!, column] instead
1 Answers

DataFrame is a two-dimensional object so you cannot index into it using one index (what you attempt to with df[:column_name]). You either should get a property like:

countmap(df.column_name)

or if you prefer to use strings

countmap(df."column_name")

or if you want to use indexing then you have to use two indices: row selector and column selector so this:

countmap(df[:, :column_name])

or

countmap(df[!, :column_name])

works. The difference is that df[!, :column_name] accesses the column without copying it while df[:, :column_name] makes a copy. Also note that you can also use strings instead of Symbols here like df[!, "column_name"] or df[!, "column_name"].

All the rules of indexing into a data frame are described here.

Related