Articles → Pandas → Series In Pandas

Series In Pandas






What Is A Series In Pandas?





Example




import pandas as pd
my_list = [10,20,30]
print(pd.Series(my_list))




Picture showing the output of series in pandas
Click to Enlarge


Customizing The Labels In Series




import pandas as pd

my_list = [10,20,30]
labels = ['I', 'II', 'III']
print(pd.Series(my_list, labels))


Picture showing the output of series after customizing labels
Click to Enlarge



  1. Dtype means the type of data a series holds.
  2. Number of elements in label array should be same as list.

Converting Numpy Array To Series




import numpy as np
import pandas as pd

my_list = [10,20,30]
arr = np.array(my_list)

print(pd.Series(arr))


Picture showing the output of converting NumPy array to series
Click to Enlarge


Converting Dictionary Into Series




import pandas as pd

d = {'a':10,'b':20,'c':30}
print(pd.Series(d))




Picture showing the output of converting dictionary to series
Click to Enlarge


Print Series




import numpy as np
import pandas as pd


d = {'a':10,'b':20,'c':30}

ser = pd.Series(d)

# Printing the series
print(ser['a'])





Using Labels As Data





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, April 10, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250