First page Back Continue Last page Overview Image

Fixing the Problem

import pandas as pd

import numpy as np

data = pd.Series(np.random.randn(10),

index=[['a', 'a', 'a',

'c', 'c', 'c',

'b', 'b', 'b',

'd'],

[1, 2, 3, 1, 2, 3, 1, 2, 2, 3]])

data.sort_index(inplace=True)

print(data["a" : "c"])

a 1 -0.876993

2 0.077060

3 0.212268

b 1 -0.223781

2 -0.489879

2 -0.232342

c 1 -1.532492

2 1.232021

3 0.960212

dtype: float64

The index needs to be sorted!