1
import pandas as pd

d = {'Belmont': 832.05420000000004,
 'Cupertino': 860.44169999999997,
 'Hillsborough': 951.95729537366503,
 'Los Altos': 1011.239,
 'Menlo Park': 877.91989999999998,
 'Palo Alto': 1196.6677,
 'Portola Valley': 883.11688311688295,
 'San Francisco': 891.23050000000001,
 'Tiburon': 924.68089999999995,
 'Woodside': 831.98380566801609}
s = pd.Series(d)
s.sort()

what is method to get the position in this sorted list? e.g. in the above list "Belmont" is the 2nd.

s.values.searchsorted(s.loc["Belmont"])

is there a better way to do this?

Dyno Fu
  • 8,753
  • 4
  • 39
  • 64
  • yes, it looks the same, although i don't think the accepted answer is better than `searchsorted()` ... – Dyno Fu Apr 04 '15 at 17:35
  • i think the best way is `s.index.get_loc("Belmont")` since the list is sorted. http://stackoverflow.com/questions/17244049/finding-label-location-in-a-dataframe-index-pandas – Dyno Fu Apr 04 '15 at 17:42

0 Answers0