Create a Pandas Series from Array
A Pandas Series is a one-dimensional labeled array that stores various data types, including numbers (integers or floats), strings, and Python objects. It is a fundamental data structure in the Pandas library used for efficient data manipulation and analysis. In this guide we will explore two simple methods to create a Pandas Series from a NumPy array.
Creating a Pandas Series Without an Index
By default when you create a Series from a NumPy array Pandas automatically assigns a numeric index starting from 0. Here pd.Series(data)
converts the array into a Pandas Series automatically assigning an index.
import pandas as pd
import numpy as np
data = np.array(['a', 'b', 'c', 'd', 'e'])
s = pd.Series(data)
print(s)
Output:

Explanation:
- The default index starts from 0 and increments by 1.
- The data type (
dtype: object
) means it stores text values
Creating a Pandas Series With a Custom Index
In this method we specify custom indexes instead of using Pandas' default numerical indexing. This is useful when working with structured data, such as employee IDs, timestamps, or product codes where meaningful indexes enhance data retrieval and analysis.
import pandas as pd
import numpy as np
data = np.array(['a', 'b', 'c', 'd', 'e'])
s = pd.Series(data, index=[1000, 1001, 1002, 1003, 1004])
print(s)
Output:

Explanation:
- Custom indexes (1000, 1001, 1002…) replace the default ones and allow meaningful data representation.
- Custom indexing enhances data retrieval, and make easier to access specific values directly using meaningful labels (e.g.,
s[1002]
instead ofs[2]
).
Creating a Pandas Series from a NumPy array is simple and efficient. You can use the default index for quick access or assign a custom index for better data organization.