Creating a Series
A Series can be born from all sorts of data — a plain list, a NumPy array, a dictionary, even a single value. Every one of them starts with the same import, then a call to pd.Series(...).
Play with the builder below to preview each source, then run the real code in the panels underneath.
Pick a source of data — see the code that builds it and the Series it produces.
import pandas as pd cities = ['Mumbai', 'Delhi', 'Bengaluru', 'Chennai'] s = pd.Series(cities) print(s)
💡 List: Most common way. Pandas auto-numbers the index from 0.
1Method 1 — The empty Series
Sometimes you need to start with nothing and fill it in later. Calling pd.Series() with no arguments creates an empty Series.
2Method 2 — From a Python list
This is the most common way. Pandas automatically creates a default integer index starting from 0.
Beyond the default: pass index=... to give every value a meaningful label of your own.
index list must be the same length as the data list — one label per value.3Method 3 — From a NumPy ndarray
Pandas is built on top of NumPy, so turning an array into a Series is seamless and efficient.
4Method 4 — From a dictionary
This one is powerful: the dictionary's keys automatically become the Series' index labels, and the values become the data.
5Method 5 — From a scalar (single value)
Want a Series where every element is the same? Give a single value — but you must also provide an index, so Pandas knows how many times to repeat it.
index with a scalar and Pandas has no idea how long the Series should be — you'll get an error. The index does double duty here: it sets both the labels and the length.6Recap — five ways in
| Source | Example | Index you get |
|---|---|---|
| Empty | pd.Series() | none (empty) |
| List | pd.Series([1, 2, 3]) | default 0, 1, 2 |
| List + index | pd.Series(data, index=labels) | your labels |
| NumPy array | pd.Series(np.array([...])) | default 0, 1, 2 |
| Dictionary | pd.Series({'a': 1}) | the dict keys |
| Scalar | pd.Series(9, index=[...]) | your labels (required) |
You build a Series from a dictionary. What becomes the index?
Which creation method REQUIRES you to pass an index?