In [ ]:
import numpy as np
import pandas as pd
x = np.array([10, 20, 30, 40])
xs = pd.Series(x)
xs.index = [3, 1, 4, 9]
print(xs.iloc[-1])
y = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
print(y)

print(f"Printing based on index: {y.iloc[0]}")

print(f"Printing based on labels: {y['a']}")

Use iloc and loc to to access elements of a Series, by index and by label, respectively.

loc supports lookup by slicing like this -- xs.loc[3:]

In [ ]: