I want to return the longest string in list in a dataframe. The original data will look like:
items
['pants','hat']
['clothes']
['mouse']
My desired output is:
items longest_str
['pants','hat'] ['pants']
['clothes'] ['clothes']
['mouse','xx'] ['mouse']
My code is :
def longest(i):
return max(i,key=len)
for i in range(0:2):
print(df['items'][i])
print(longest(df['items'][i]))
but it does not print out what I want. My ultimate goal is to find the longest string in the whole dataframe. Please suggest any other optimal way to approach it