Pandas is an open-source Python library. It provides us with some new data structures, such as Series and DataFrame. A pandas Series is a one-dimensional data structure. It is similar to NumPy one-dimensional array or Python list. But, the main difference is it is labeled. In this article, we will discuss how to create a pandas Series.
We can use the pandas.Series() constructor to create a pandas Series.
import pandas list1 = [1, 2, 3, 4, 5] series1 = pandas.Series(list1) print(series1) series2 = pandas.Series(list1, index=["First", "Second", "Third", "Fourth", "Fifth"]) print(series2)
Here, we are first importing the pandas library. After that, we are initializing a Python list. The list “list1” contains five elements or five integers. We are using this list to create a pandas Series “series1.”
The Python statement print(series1) will print the following output:
0 1 1 2 2 3 3 4 4 5 dtype: int64
Please note that pandas Series is a labeled data structure. So, the left-hand side column indicates …






0 Comments