Tuesday 16 February 2021

1.1 Series in Pandas

1.1 Series in Pandas

Pandas:

Pandas is a Python Library. Pandas stands for “Panel Data System”

Series:

Series is a data structure. Which can store 1 D homogeneous data.

DataFrame:

DataFrame is a 2 D Data Structure, which can store 2 D Heterogeneous data.

Series

Data Frame

Series is a data structure

Data is a data structure

Series is 1 Dimensional

DataFrame is 2 Dimensional

Series is Homogeneous

DataFrame is Heterogeneous

Value Mutable

Value Mutable

Size Immutable

Size Mutable

 

 

How To create:

1.       Using Python Sequence (List, Tuple, String)

2.       Using ndarray

3.       Using Python Dictionary

4.       Using Scalar Value

 

Create a Series using List

 




Assignment: 1 (Create a Series)

1.       WAP in Python to create a Series using Python Sequence [4, 6, 8, 10].

2.       WAP in Python to create a Series using Python Sequence (11, 21, 31, 41).

3.       WAP in Python to create a Series using individual characters ‘o’, ’h’, and ‘o’.

4.       WAP in Python to create a Series using a string “So Funny”.

5.       WAP in Python to Create a Series using three words: “I”, “am”, “Laughing”.

6.       WAP to create a Series using ndarray that has 5 elements in the range 24 to 64.

7.       WAP to create a Series using ndarray that is created by that is created by tilling a list [3, 5] twice.

8.       WAP to create a Series using dictionary that stores the number of students in each section of class 12 in your school.

9.       WAP to create a Series that store the initial budget allocated 500000/ - each for the quarters of the year: Qtr1, Qtr2, Qtr3, Qtr4.

10.   Total numbers of medals to be won is 200 in the games held every alternate year. WAP to Create a Series that store these medals for games to be help in the decade 2020-2029.

 

 

#Series: 1 : - WAP in Python to create a Series using Python Sequence [4, 6, 8, 10].

 

import pandas as pd

L=[4, 6, 8, 10]

S=pd.Series(L)

print(S)

 

 

#Series: 2 : - WAP in Python to create a Series using Python Sequence (11, 21, 31, 41).

 

import pandas as pd

T=(11, 21, 31, 41)

S=pd.Series(T)

print(S)

 

#Series: 3 : - WAP in Python to create Series using individual

#characters ‘o’, ’h’, and ‘o’.

import pandas as pd

C=['o','h','o']

S=pd.Series(C)

print(S)

 

 

#Series: 4 : - WAP in Python to create Series using a string “So Funny”.

import pandas as pd

C="So Funny"

S=pd.Series(C)

print(S)

 

#Series: 5 : - WAP in Python to create Series using three words: “I”, “am”, “Laughing”.

import pandas as pd

C=["I","am","Laughing"]

S=pd.Series(C)

print(S)

 

 

#Series: 6 : - WAP in Python to create Series using ndarray that has 5 elements

#in the range 24 to 64.

import pandas as pd

import numpy as np

E=np.linspace(24,64,5)

S=pd.Series(E)

print(S)

 

 

#Series: 7 : - WAP in Python to create Series using ndarray that is created

#by by tilling a list [3, 5] twice.

import pandas as pd

import numpy as np

E=np.tile([3,5],2)

S=pd.Series(E)

print(S)

 

 

#Series: 8 : - WAP to create a Series using dictionary that stores the number

#of students in each section of class 12 in your school.

import pandas as pd

D={'A':42,'B':48,'C':51,'D':47}

S=pd.Series(D)

print(S)

 

 

#Series: 9 : - WAP to create a Series that store the initial budget allocated

#500000/ - each for the quarters of the year: Qtr1, Qtr2, Qtr3, Qtr4.

import pandas as pd

I=['Qtr1','Qtr2','Qtr3','Qtr4']

S=pd.Series(500000,index=I)

print(S)

 

 

#Series: 10 : - Total numbers of medals to be won is 200 in the games held every

#alternate year. WAP to Create a Series that store these medals for games to be

#help in the decade 2020-2029.

import pandas as pd

I=list(range(2020,2029,2))

S=pd.Series(200,index=I)

print(S)

 

 

No comments:

Post a Comment