Series Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

SERIES PROGRAM

#write a Python program to create a


Series to store 3 students
Percentage Using dictionary and
print all the elements that are above
75 percentage.( using dictionary)

Import pandas as pd
D = {"karamjeet": 17, "Mandeep":
17, "TAMAN": 17}
s = pd.Series(D)
print(s[s > 75])

OUTPUT:-

Series([], dtype: int64)


# write a Python program to create a
Series object that stores the Initial
budget allocated (40000/- each) for
the four quarters of the year: Qtr1,
Qtr2, Qtr3 and Qtr4.( series using
scalar value)

import pandas as pd
Budget = pd.Series(40000,
index={'qtr1', 'qtr2', 'qtr3', 'qtr4'})
print(Budget)

Output:-
qtr2 40000
qtr4 40000
qtr1 40000
qtr3 40000
dtype: int64
#write a Python program to create a
Series object that stores the
Employee names as index and their
Salary as values.(SERIES USING
NUMPY ARRAY )

import pandas as pd
import numpy as np
section = ['A', 'B', 'C']
contribution = np.array([1200, 1400,
np.nan])
s = pd.Series(data=contribution,
index=section)
print(s)

Output:-
A 1200.0
B 1400.0
C NaN
dtype: float64
#Write a Python program to create a Series object
with Employee names as the index and their
salaries as values. Accept the name of the employee
whose salary needs to be changed, along with the
new salary, and update it in the Series . (PYTHON
PROGRAM FOR MODIFYING OR UPDATING
EXISTING VALUES OF SERIES OBJECT).

import pandas as pd
D = {'RANA': 50000, 'RAMA': 40000, 'AMAN': 34000,
'ASHISH': 53000}
S = pd.Series(D)
print("Employees salary before updating")
print(S)
print("")
opt = input("Do you want to update the salary of the
employee (y/n)?: ")
if opt.lower() == 'y':
name = input("Enter the name of employee: ")
if name in S.index:
new_salary = float(input("Enter the new salary: "))
S[name] = new_salary
print("Salary updated successfully:")
print("Employees salary after updating")
print(S)
else:
print("Employee not found in record.")
else:
print("Thank You!!!")
Output:-
Employees salary before updating
RANA 50000
RAMA 40000
AMAN 34000
ASHISH 53000
dtype: int64

Do you want to update the salary of


the employee (y/n)?: Y
Enter the name of employee: AMAN
Enter the new salary: 60000
Salary updated successfully:
Employees salary after updating
RANA 50000
RAMA 40000
AMAN 60000
ASHISH 53000
dtype: int64
# create a program in python to perform
following mathematical Operations on Two
Series objects: (i) Addition (ii) Subtraction
(iii) Multiplication (iv) Division.
import pandas as pd
S1=pd.Series([10,20,30,40,50,60],index=['a','b','c','d','e','f'])
S2=pd.Series([2,5],index=['a','b'])
print("The addition of two series object is :")
print(S1+S2)
print("The Subtraction of two series object is:")
print(S1-S2)
print("the multiplication of two series object is :")
print(S1*S2)
print("the division of two series object is:")
print(S1/S2)

OUTPUT:-
The addition of two series object is :
a 12.0
b 25.0
c NaN
d NaN
e NaN
f NaN
dtype: float64
The Subtraction of two series object is:
a 8.0
b 15.0
c NaN
d NaN
e NaN
f NaN
dtype: float64
the multiplication of two series object is :
a 20.0
b 100.0
c NaN
d NaN
e NaN
f NaN
dtype: float64
the division of two series object is:
a 5.0
b 4.0
c NaN
d NaN
e NaN
f NaN
dtype: float64

# write a Python program to create a Series


using list and display the following attributes of
the Series: (i) index (ii) dtype (iii) size (iv) shape
(v) hasnans
import pandas as pd
L = [10, 20, 30, 40, 50]
S = pd.Series(L, index=['a', 'b', 'c', 'd', 'e'])
print("The index of the series is:", S.index)
print("The datatype of the series is:", S.dtype)
print("The size of the series is:", S.size)
print("The shape of the series is:", S.shape)
print("The NaN of the series is:", S.hasnans)

OUTPUT:-
The index of the series is: Index(['a', 'b', 'c', 'd', 'e'],
dtype='object')
The datatype of the series is: int64
The size of the series is: 5
The shape of the series is: (5,)
The NaN of the series is: False

#write a Python program to create a


Series using list of Marks of 10
students and display first 5 Students’
marks and Last 2 Students’ marks from
Series object.( USING HEAD AND TIAL
IN SERIES).
import pandas as pd
Marks = [10, 20, 30, 40, 50, 60, 70, 80]
S = pd.Series(Marks, index=['stud1', 'stud2',
'stud3', 'stud4', 'stud5', 'stud6', 'stud7',
'stud8'])
print(S.head())
print("\n")
print("the last two students' marks are:")
print(S.tail(2))

OUTPUT:-
stud1 10
stud2 20
stud3 30
stud4 40
stud5 50
dtype: int64

the last two students' marks are:


stud7 70
stud8 80
dtype: int64
INDEX
PROGRAM (REPORT)
1. SERIES
●SERIES CREATION USING
DIFFERENT METHOD
●SERIES ATTRIBUTES
●ACCESSING ELEMENTS
●MATHMETICAL OPERATION

2. DATAFRAME
● DATFRAME CREATION
USING DIFFERENT METHOD
●DATAFRAME ATTRIBUTES
●DATAFRAME AND CSV
●OPERATION ON DATAFRAME

You might also like