简体   繁体   中英

Trying to find top 10 most common routes in a list of routes

I am trying to use excel to find the most common routes in a list of routes (start city/state and end city/state) that looks like this:

SACRAMENTO  CA   SANTA FE SPRINGS   CA
FRESNO  CA   SAN DIEGO  CA
FIONA   TX   LOS ANGELES    CA
ELMWOOD PARK    NJ   MORENO VALLEY  CA
RICHMOND    CA   VERNON     CA
TORRANCE    CA   OKLAHOMA CITY  OK
LOUISVILLE  KY   MANCHESTER     PA
SAN DIEGO   CA   PHOENIX    AZ
SAN DIEGO   CA   FRESNO     CA
SAN DIEGO   CA   CONLEY     GA
WACO    TX   COMMERCE   CA
MARSHVILLE  NC   HARRINGTON     DE
SYRACRUSE   NY   SOUTH WINDSOR  CT
CARTHAGE    MO   GORDONSVILLE   VA
NEW BERLIN  NY   FORT WORTH     TX
HERMITAGE   PA   CARROLLTON     TX
BETHLEHEM   PA   COTTONWOOD     AL
SAN DIEGO   CA   OREGON CITY    OR
SAN DIEGO   CA   KENT   WA
... and so on

I am attempting to use excel to do this because I think it can with pivot tables, but I'm not sure. If it comes down to it I can use python as well. I'm looking for tips on either how to use excel to do this or how I should set up the algorithm in Python. Thank you, any help is appreciated.

This will give you what you are looking for:

df = df.groupby(['Col1', 'Col2']).size().reset_index(name='Freq') 
#Col1 and #Col2 is the name columns of your df

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM