{reversing and indexing together} in pandas. Not getting expected output

Question:

series = pd.Series(['A', 'B', 'C','D'], index=['a', 'b', 'c', 'd'])

I want:

c    C
b    B
a    A
dtype: object

I tried:

series['a':'c':-1]

but I’m getting:

Series([], dtype: object)
Asked By: VVY

||

Answers:

series['c':'a':-1]

output:

c    C
b    B
a    A
dtype: object
Answered By: VVY

You can also use series.loc to obtain the same result.

series.loc['c'::-1]

c    C
b    B
a    A
dtype: object
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.