Given a Pandas DataFrame with lists stored in several of the columns, is there a simple way to find the column name which contains the longest list for each row?
For example, with this data:
positive negative neutral
1 [marvel, moral, bold, destiny] [] [view, should]
2 [beautiful] [complicated, need] []
3 [celebrate] [crippling, addiction] [big]
I want to identify "positive" as the column with the longest list for row 1 and "negative" for rows 2 and 3.
I thought I could use str.len()
to calculate the list lengths and idmax()
to get the column names, but can't figure out how to combine them.