LearnWave
Learn it. Master it.

Data Handling using Pandas - I

Accessing a Series

Use indexing, slicing, attributes and head/tail/count on a Series.

You can reach values in a Series in two ways:

  • positional index: the position, starting at 0;
  • labelled index: the labels you gave.

Slicing works with both, but with one important difference:

  • a positional slice excludes the end position: s[1:3] gives the values at positions 1 and 2;
  • a label slice includes the end label: s['Jan':'Mar'] gives Jan, Feb and Mar.

s[::-1] gives the series in reverse order. Slices can also be used to change values: s[1:3] = 0.

Useful attributes: name (the series' name), index.name, values (the values as an array), size (number of values) and empty (True if there are no values).

Useful methods: head(n) and tail(n) show the first or last n values (5 if n is not given), and count() counts the values that are not NaN (not missing). Positions exclude the end; labels include it.

Positions exclude the end; labels include it.

Practise this lesson

Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.

No account, no email address. Opens the real product.