Pandas Series
Series is like one dimensional array or a column in a table and can be hold any type data. Furthermore, pandas series can be created in two ways.
1- Create a Pandas Series with Default Indices-
In this method, you can create a series by passing list inside Series() method. As a result, the method will create a series having indices 0, 1, 2, 3.
import pandas as pd l=[1,5,9,13] ser=pd.Series(l) print(ser) Output: 0 1 1 5 2 9 3 13 dtype: int64
2- Create a Pandas Series with Customize Indices-
In this method, you can create a series by passing a list and a list of indices inside Series() method. As a result, the below program will create a series having indices a, b, , c and d.
import pandas as pd l=[1,5,9,13] i=["a","b","c", "d"] ser=pd.Series(l, index=i) print(ser) Output: a 1 b 5 c 9 d 13 dtype: int64
Access Individual Element from a Series
You can also access an element like you access in list see the below example:
import pandas as pd l=[1,5,9,13] i=["a","b","c","d"] ser=pd.Series(l,index=i) print(ser["c"])
Output: 9
Print Type of Series
import pandas as pd l=[1,5,9,13] i=["a","b","c", "d"] ser=pd.Series(l, index=i) print(type(ser)) Output: <class 'pandas.core.series.Series'>