猿问

查找数据框中列表中的最后一个值

拜托,我想在数据框中找到客户端中的最后一个值,我该怎么做?


例子 :


df = pd.DataFrame({'date': 

    ['2018-06-13', '2018-06-14', '2018-06-15', '2018-06-16'],

    'gain': [[10, 12, 15],[14, 11, 15],[9, 10, 12], [6, 4, 2]],

    'how':  [['customer1', 'customer2', 'customer3'], 

            ['customer4','customer5','customer6' ],

            ['customer7', 'customer8', 'customer9'],

            ['customer5', 'customer6', 'customer10'] ]}



   df : 

           date       gain                    how

    0 2018-06-13  [10, 12, 15]    [customer1, customer2, customer3]

    1 2018-06-14  [14, 11, 15]    [customer4, customer5, customer6]

    2 2018-06-15  [9, 10, 12]     [customer7, customer8, customer9]

    3 2018-06-16  [6, 4, 2]       [customer5, customer6, customer10]

I want to do a function that returns the last gain in the dataframe.

example :

 for the customer5 = 6

 for the customer4 = 14

 for the customer20 = 'not found' 

太感谢了


猛跑小猪
浏览 162回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答