Python | Pandas Series - GeeksforGeeks

17 Jan, 2019
Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The axis labels are collectively called index. Pandas Series is nothing but a column in an excel sheet.Labels need not be unique but must be a hashable type. The object supports both integer and label-based indexing and provides a host of methods for performing operations involving the index.In this article, we are using nba.csv file.
We will get a brief insight on all these basic operations which can be performed on Pandas Series :
Creating a Series
Accessing element of Series
Indexing and Selecting Data in Series
Binary operation on Series
Conversion Operation on Series
In the real world, a Pandas Series will be created by loading the datasets from existing storage, storage can be SQL Database, CSV file, and Excel file. Pandas Series can be created from the lists, dictionary, and from a scalar value etc. Series can be created in different ways, here are some ways by which we create a series:
Creating a series from array: In order to create a series from array, we have to import a numpy module and have to use array() function.
Output :
 Creating a series from Lists:In order to create a series from list, we have to first create a list after that we can create a series from list.
Output :
For more details refer to Creating a Pandas Series 
There are two ways through which we can access element of series, they are :
Accessing Element from Series with Position
Accessing Element Using Label (index)
Accessing Element from Series with Position : In order to access the series element refers to the index number. Use the index operator [ ] to access an element in a series. The index must be an integer. In order to access multiple elements from a series, we use Slice operation.
Accessing first 5 elements of Series
Output : Accessing Element Using Label (index) :In order to access an element from series, we have to set values by index label. A Series is like a fixed-size dictionary in that you can get and set values by index label.
Accessing a single element using index label
Output :
o

For more details refer to Accessing element of Series 
Indexing in pandas means simply selecting particular data from a Series. Indexing could mean selecting all the data, some of the data from particular columns. Indexing can also be known as Subset Selection.
Indexing a Series using indexing operator [] :Indexing operator is used to refer to the square brackets following an object. The .loc and .iloc indexers also use the indexing operator to make selections. In this indexing operator to refer to df[ ].
Now we access the element of series using index operator [ ].
Output : Indexing a Series using .loc[ ] :This function selects data by refering the explicit index . The df.loc indexer selects data in a different way than just the indexing operator. It can select subsets of data.
Now we access the element of series using .loc[] function.
Output : Indexing a Series using .iloc[ ] :This function allows us to retrieve data by position. In order to do that, we’ll need to specify the positions of the data that we want. The df.iloc indexer is very similar to df.loc but only uses integer locations to make its selections.
Now we access the element of Series using .iloc[] function.
Output : 
We can perform binary operation on series like addition, subtraction and many other operation. In order to perform binary operation on series we have to use some function like .add(),.sub() etc..Code #1:
Now we add two series using .add() function.
Output :Code #2:
Now we subtract two series using .sub function.
Output :For more details refer to Binary operation methods on series 
In conversion operation we perform various operation like changing datatype of series, changing a series to list etc. In order to perform conversion operation we have various function which help in conversion like .astype(), .tolist() etc.Code #1:
Output : Code #2:
Output :
Binary operation methods on series:
 Pandas series method:
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, ...
Learn C++ Programming Step by Step - A 20 Day Curriculum!
Must Do Coding Questions for Product Based Companies
CSS Interview Questions and Answers
50 Common Ports You Should Know
GeeksforGeeks Jobathon - Are You Ready For This Hiring Challenge?
How to Find Length of String in Bash Script?
Samsung R&D Internship Interview Experience (On-Campus)
Types of Distributed System
How to use Material-UI with Next.js ?