Last Updated : 11 Jul, 2025
A Pandas Series is like a single column of data in a spreadsheet. It is a one-dimensional array that can hold many types of data such as numbers, words or even other Python objects. Each value in a Series is associated with an index, which makes data retrieval and manipulation easy. This article explores multiple ways to create a Pandas Series with step-by-step explanations and examples.
Creating an Empty Pandas SeriesAn empty Series contains no data and can be useful when we plan to add values later. we can create an empty Series using the pd.Series()
function. By default an empty Series has a float64
data type. If we need a different data type specify it using the dtype
parameter
import pandas as pd
ser = pd.Series()
print(ser)
Output:
Creating a Series from a NumPy ArraySeries([], dtype: float64)
If we already have data stored in a NumPy array we can easily convert it into a Pandas Series. This is helpful when working with numerical data.
Python
import pandas as pd
import numpy as np
data = np.array(['g', 'e', 'e', 'k', 's'])
ser = pd.Series(data)
print(ser)
Output:
Series Using Numpy Arrays Creating a Series from a Listwe can create a Series by passing a Python list to the pd.Series()
function. Pandas automatically assigns an index to each element starting from 0. T
his is a simple way to store and manipulate data.
import pandas as pd
data_list = ['g', 'e', 'e', 'k', 's']
ser = pd.Series(data_list)
print(ser)
Output:
Creating a Series from a DictionaryA dictionary in Python stores data as key-value pairs. When we convert Dictionary into a Pandas Series the keys become index labels and the values become the data. This method is useful for labeled data preserving structure and enabling quick access. Below is an example.
Python
import pandas as pd
data_dict = {'Geeks': 10, 'for': 20, 'geeks': 30}
ser = pd.Series(data_dict)
print(ser)
Output:
Series using Dictionary Creating a Series Using NumPy FunctionsIn order to create a series using numpy function. Some commonly used NumPy functions for generating sequences include numpy.linspace()
for creating evenly spaced numbers over a specified range and numpy.random.randn()
for generating random numbers from a normal distribution. This is particularly useful when working with scientific computations, statistical modeling or large datasets
import numpy as np
import pandas as pd
ser = pd.Series(np.linspace(1, 10, 5))
print(ser)
Output:
Series using Numpy Functions Creating a Series Usingrange()
The range()
function in Python is commonly used to generate sequences of numbers and it can be easily converted into a Pandas Series. This is particularly useful for creating a sequence of values in a structured format without need of manually specify each element. Below is an how range()
can be used to create a Series.
import pandas as pd
ser = pd.Series(range(5, 15))
print(ser)
Output:
Series using range() Creating a Series Using List ComprehensionList comprehension is a concise way to generate sequences and apply transformations in a single line of code. This method is useful when we need to create structured sequences dynamically. Below is an example demonstrating how list comprehension is used to create a Series with a custom index.
Python
import pandas as pd
ser=pd.Series(range(1,20,3), index=[x for x in 'abcdefg'])
print(ser)
Output:
Using List ComprehensionPandas provides multiple ways to create a Series. Understanding these methods will help us work efficiently with data in Pandas making it easier to analyze and process real-world datasets. With these examples we are now able to create and work with Pandas Series in different ways. Happy coding!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4