I have a dataframe like this:
fly_frame:
          day    plcae
0  [1,2,3,4,5]       A
1    [1,2,3,4]       B
2        [1,2]       C
3     [1,2,3,4]      D
If I want to find the max value in each entry in the day column.
For example:
fly_frame:
          day    plcae
0           5       A
1           4       B
2           2       C
3           4       D
What should I do?
Thanks for your help.
df.day.apply(max)
#0    5
#1    4
#2    2
#3    4
                        Use apply with max:
#if strings
#import ast
#print (type(df.loc[0, 'day']))
#<class 'str'>
#df['day'] = df['day'].apply(ast.literal_eval)
print (type(df.loc[0, 'day']))
<class 'list'>
df['day'] = df['day'].apply(max)
Or list comprehension:
df['day'] = [max(x) for x in df['day']]
print (df)
   day plcae
0    5     A
1    4     B
2    2     C
3    4     D
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With