A Series is a one-dimensional labeled data structure that can contain data of any type (integer, float, etc.). The labels are known as index. A Series contain homogeneous data.
A Series can be visualized as a one-dimensional NumPy array, for example:
Red | Blue | Green | Black | Yellow | White | Brown |
The size of a Series is immutable but data values are mutable.
The syntax for creating a Pandas Series is:
pandas.DataFrame( data, index, dtype, copy) |
data, index, columns, dtype, copy are its parameters –
Pandas Series can be created from constant values, lists, maps, dictionary, ndarray, etc. Let us look at some basic examples of creating a Series.
import pandas as pd # creating an empty Series series = pd.Series() print(series) |
The output obtained is:
Series([], dtype: float64) |
import pandas as pd # creating a Series using list student = [‘John’,15,87.5] series = pd.Series(student) print(series) |
This gives the following output:
0 John 1 15 2 87.5 dtype: object |
import pandas as pd # creating a Series using list with labels student = [‘John’,15,87.5] labels = [‘Name’,’Age’,’Marks’] series = pd.Series(student,labels) print(series) |
Output is:
Name John Age 15 Marks 87.5 dtype: object |
import pandas as pd # a dictionary student = {‘Name’: ‘John’, ‘Age’: 20, ‘Marks’: 87.5} # creating a Series using dictionary series = pd.Series(student,index=[‘Name’,’Age’,’Country’,’Marks’]) print(series) |
The output obtained is as follows:
Name John Age 20 Country NaN Marks 87.5 dtype: object |
The missing values are filled with NaN.
In this article, we have looked at the main data structures of Pandas – Series. In the upcoming articles, we will focus on more operations on DataFrame and Series.
In this tutorial, we will focus on MapReduce Algorithm, its working, example, Word Count Problem,…
Learn how to use Pyomo Packare to solve linear programming problems. In recent years, with…
In today's rapidly evolving technological landscape, machine learning has emerged as a transformative discipline, revolutionizing…
Analyze employee churn, Why employees are leaving the company, and How to predict, who will…
Airflow operators are core components of any workflow defined in airflow. The operator represents a…
Machine Learning Operations (MLOps) is a multi-disciplinary field that combines machine learning and software development…