python - pandas pivot_table apply aggfunc last instance -


i have made pivot table various columns , have applied aggfunc np.sum , first , count. want last instance of corresponding value of column dataframe. there function serve purpose?

i think can use

aggfunc='last' 

sample:

df = pd.dataframe({ 'age':[35, 37, 40, 29, 31, 26, 28],                    'city':['b', 'ch', 'la', 'ch', 'b', 'b', 'ch'],                    'position':['m','m','m','p', 'p','m','m']}) print (df)    age city position 0   35    b        m 1   37   ch        m 2   40   la        m 3   29   ch        p 4   31    b        p 5   26    b        m 6   28   ch        m  print (df.pivot_table(index='position', columns='city', values='age', aggfunc='last')) city         b    ch    la position                   m         26.0  28.0  40.0 p         31.0  29.0   nan 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -