station_stat_full = station_stat_full.query('count > 30') good_stat2 = station_stat_full.pivot_table(index='name', values='time_spent', aggfunc=['median', 'count']) good_stat2.columns=['median_time', 'stations'] print(good_stat2.head(5))