Reuven M. Lerner @lernerpython.com · 25d

Trying to use .loc to retrieve a slice in #Python #Pandas? If the index repeats, you need to sort it: s = Series([10, 20, 30], index=list('aba')) s.loc['a':'b'] # KeyError: "Cannot get left slice bound for non-unique label: 'a'" s.sort_index().loc['a':'b'] # works!

2 likes 0 replies

?