I am trying to get the string lengths for different columns. Seems quite straightforward with:
df['a'].str.len()
But I need to apply it to multiple columns. And then get the minimum on it.
Something like:
df[['a','b','c']].str.len().min
I know the above doesn't work, but hopefully you get the idea. Column a
, b
, c
all contain names and I want to retrieve the shortest name.
Also because of huge data, I am avoiding creating other columns to save on size.
I think you need list comprehension, because
string
function works only withSeries
(column
):Another solution with
apply
:Sample:
Timings:
Conclusion:
apply
is faster, but not works withNone
.EDIT by comment: