根据熊猫数据帧分组并选择最常用的值
import pandas as pdfrom scipy import stats source = pd.DataFrame({'Country' : ['USA', 'USA', 'Russia','USA'], 'City' : ['New-York', 'New-York', 'Sankt-Petersburg', 'New-York'], 'Short name' : ['NY','New','Spb','NY']})print source.groupby(['Country','City']). agg(lambda x: stats.mode(x['Short name'])[0])
largeQ
杨__羊羊
相关分类