Give a dataframe like this :
dataframe = DataFrame(col1 = rand(3),
col2 = [['a'],['a','b','c'],['a','c']])
How can I get the longest list in col2?
I tried with :
dataframe[partialsortperm(dataframe.col2, 1, rev=true), :]
but It returns ['a','c'] instead of ['a','b','c].
CodePudding user response:
[EDIT] Actually, you want argmax:
julia> argmax(length, dataframe.col2)
3-element Vector{Char}:
'a': ASCII/Unicode U 0061 (category Ll: Letter, lowercase)
'b': ASCII/Unicode U 0062 (category Ll: Letter, lowercase)
'c': ASCII/Unicode U 0063 (category Ll: Letter, lowercase)
[pre-EDIT answer below:]
I think you want to use findmax:
julia> findmax(length, dataframe.col2) # returns (max length, index)
(3, 2)
julia> dataframe.col2[findmax(length, dataframe.col2)[2]]
3-element Vector{Char}:
'a': ASCII/Unicode U 0061 (category Ll: Letter, lowercase)
'b': ASCII/Unicode U 0062 (category Ll: Letter, lowercase)
'c': ASCII/Unicode U 0063 (category Ll: Letter, lowercase)
