LearnWave
Learn it. Master it.

Data Handling using Pandas - I

Pandas and creating a Series

Create Series from lists, NumPy arrays and dictionaries.

NumPy, Pandas and Matplotlib are Python libraries for scientific and analytical work. Pandas ('PANel DAta') makes it easy to load, organise and analyse data. Install it with the command pip install pandas, and import it with import pandas as pd.

Pandas has two main data structures: the Series and the DataFrame.

A Series is a one-dimensional array of values, where each value has a label, called its index. If you do not give labels, the index is 0 to N − 1.

Ways to create a Series:

  • from a list: pd.Series([5, 15, 25]) gives index 0, 1, 2;
  • with your own labels: pd.Series([5, 15, 25], index=['Jan', 'Feb', 'Mar']);
  • from a NumPy array: pd.Series(array1). The number of index labels must equal the number of values, or Python raises a ValueError;
  • from a dictionary: the keys become the index. pd.Series({'Maths': 90, 'Hindi': 85}) has index Maths and Hindi.

A Series can hold any type of value: numbers, strings and so on. A Series is one labelled column.

A Series is one labelled column.

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.