Python Program
Python Program
PANDAS SERIES-I
1A. To create a Series from a list with values ONE, TWO, THREE, FOUR, FIVE, SIX
To print the Series with default index values
To print the Series and give it the index values of ‘a’, ‘b’, ‘c’, ‘d’, ‘e’
PROGRAM
import pandas as pd
print("PRINTING SERIES WITH DEFAULT INDEX VALUES")
S1=pd.Series(['ONE','TWO','THREE','FOUR','FIVE','SIX'])
print(S1)
S1=pd.Series(['ONE','TWO','THREE','FOUR','FIVE','SIX'],index=['a','b','c','d','e','f'])
print("PRINTING SERIES WITH EXPLICITLY DEFINED INDEX VALUES")
print(S1)
1
OUTPUT
2
1B. Write a Python Program to perform the following operations:-
Create a pandas series from a dictionary of values given below.
Original dictionary = {‘a’:100, ‘b’:200, ‘c’:300, ‘d’:400, ‘e’:500}
PROGRAM
import pandas as pd
D1={‘a’:100, ‘b’:200, ‘c’:300, ‘d’:400, ‘e’:500}
print(“ORIGINAL DICTIONARY”)
print(D1)
S1=pd.Series(D1)
print(“DICTIONARYCONVERTED TO SERIES”)
print(S1)
3
OUTPUT
PYTHON PROGRAM – II
4
PANDAS SERIES-II
PROGRAM
import pandas as pd
S1=pd.Series(range(10,60,10),index=[1,2,3,4,5])
S2=pd.Series(range(2,12,2),index=[1,2,3,4,5])
#PRINTING SERIES S1
print("SERIES S1")
print(S1)
#PRINTING SERIES S2
print("SERIES S2")
print(S2)
S3=S1+S2
#PRINTING SUM OF S1 & S2
print("SUM OF S1 & S2")
print(S3)
S3=S1-S2
#PRINTING DIFFERENCE OF S1 & S2
print("DIFFERENCE OF S1 & S2")
print(S3)
S3=S1*S2
#PRINTING PRODUCT OF S1 & S2
print("PRODUCTOF S1 & S2")
5
print(S3)
S3=S1/S2import pandas as pd
# PRINTING THE QUOTIENT OF S1 & S2
print("QUOTIENTOF S1 & S2")
print(S3)
S3=S1//S2
# PRINTING INTEGER QUOTIRNT OF S1 & S2
print("INTEGER QUOTIENT OF S1 & S2")
print(S3)
OUTPUT
6
`
PYTHON PROGRAM – III
PANDAS SERIES-III
7
3A) To create a Series from an array A of values [10 20 30 40 50 60 70 80 90 100]:
i) Without range function with index values A, B, C, D, E, F, G, H, I, J -
PROGRAM
import pandas as pd
import numpy as np
A=np.array([10,20,30,40,50,60,70,80,90,100])
print("PRINTING ARRAY ELEMENTS")
print(A)
S=pd.Series(A, index=['A','B','C','D','E','F','G','H','I','J'])
print("PRINTING SERIES ELEMENT FROM ARRAY WITH DEFINED
INDEX VALUES")
print(S)
OUTPUT
8
ii) Using range function with default index values -
PROGRAM
9
import pandas as pd
import numpy as np
A=(np.arange(10,110,10))
print("PRINTING ARRAY ELEMENTS")
print(A)
S=pd.Series(A)
print("PRINTING SERIES ELEMENT FROM ARRAY")
print(S)
OUTPUT
10
PYTHON PROGRAM – IV
PANDAS SERIES-IV
11
To retrieve MARKS in a Series S1 based on the conditions given below.
The list of marks are [45.5, 67.75, 89.5, 33.25, 90.75, 70.0, 29.25, 95.5]
(i) Display all marks with value less than or equal to 40.
(ii) Display all marks with values greater than or equal to 90.
(iii) Display all marks not less than 60
(iv) Display all marks not above 40.
(v) Display all the marks other than 70.
PROGRAM
import pandas as pd
S1=pd.Series([45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5])
print("PRINTING ORIGINAL SERIES")
print(S1)
print("MARKS LESS THAN OR EQUAL TO 40")
print(S1[S1<=40])
print("MARKS GREATER THAN OR EQUAL TO 90")
print(S1[S1>=90])
print("MARKS LESS THAN 60")
print(S1[S1<60])
print("MARKS NOT ABOVE 40")
print(S1[S1<=40])
print("MARKS NOT EQUAL TO 70")
print(S1[S1!=70])
OUTPUT
12