Home > database >  Indexing in pandas. Not getting expected output
Indexing in pandas. Not getting expected output

Time:09-05

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)

CodePudding user response:

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

output:

c    C
b    B
a    A
dtype: object

CodePudding user response:

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

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

c    C
b    B
a    A
dtype: object
  • Related