Two important data structures of pandas are–Series, DataFrame -important notes

 Two important data structures of pandas are–Series, DataFrame 


1. Series Series is like a one-dimensional array like structure with homogeneous data.


Basic feature of series are 

❖ Homogeneous data

 ❖ Size Immutable

 ❖ Values of Data Mutable


2. DataFrame DataFrame is like a two-dimensional array with heterogeneous data.

 Basic feature of DataFrame are

 ❖ Heterogeneous data 

❖ Size Mutable 

❖ Data Mutable


Pandas Series It is like one-dimensional array capable of holding data of any type (integer, string, float, python objects, etc.).

 Series can be created using constructor.

 Syntax :- pandas.Series( data, index, dtype, copy) 

Creation of Series is also possible from – ndarray, dictionary, scalar value. 

Series can be created using 1. Array 2. Dict 3. Scalar value or constant


Create an Empty Series 

 import pandas as pseries 

s = pseries.Series() 

print(s) 


Output Series([], dtype: float64)




Without index e.g. 

import pandas as pd1

 import numpy as np1 

data = np1.array(['a','b','c','d'])

 s = pd1.Series(data) 

print(s) 




With index position e.g. 

import pandas as p1 

import numpy as np1

 data = np1.array(['a','b','c','d'])

 s = p1.Series(data,index=[100,101,102,103]) 

print(s)


Create a Series from Scalar 

e.g 


import pandas as pd1 

import numpy as np1 

s = pd1.Series(5, index=[0, 1, 2, 3]) 

print(s)




Post a Comment

0 Comments