我一直在尝试从 csv 文件中提取起始站和结束站最常见的组合,我遇到的问题是我正在提取所有这些组合。当试图只提取组合最多的一个时,我只得到一个数字?
def station_stats(df):
frequent_stations = df.groupby(['Start Station'])['End Station'].value_counts().mode
print('Most frequent start and end station: ', frequent_stations)
下面是我当前输出的片段:
Most frequent start and end station: <bound method Series.mode of Start Station End Station
2112 W Peterson Ave Warren Park East 8
Clark St & Berwyn Ave 5
Washtenaw Ave & Lawrence Ave 4
最佳答案
IIUC
df.groupby(['Start Station','End Station']).size().nlargest(1)
关于python - 从 csv 列中提取最常见的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50848454/