INDEX
SL.NO. DATE PROGRAM PG.NO REMARKS
A PANDAS SERIES
1 Create a Series from ndarray 2
and a dictionary of values
2 Series to display the amount of 3
sales made by salesperson
3 Updating existing values of 4
Series
4 Display Series objects using 6
iloc, loc and slicing
5 Attributes of Series objects 8
6 Mathematical operations on 9
Series
B PANDAS DATAFRAME
7 Create and display a 11
DataFrame
8 Accessing values of rows and 14
columns of a DataFrame
9 Inserting column and deleting 16
row from a DataFrame
10 Rename ,count, update and 18
replace operations on
DataFrame
11 Display the attributes of the 21
DataFrame
12 Iterations on DataFrame 22
13 Writing and reading 24
operations in a csv file
C MATPLOTLIB
14 Multiple line chart 25
15 Bar chart 26
16 Multiple bar chart from CSV 27
file
17 Histogram 28
D MYSQL 30
1
,P1. Create a series from ndarray and a dictionary of values
SOURCE CODE:
import pandas as pd
import numpy as np
si=pd.Series(np.array([23,34,45,67,78]))
print('series from ndarray')
print(si)
d1={'niya':25,'neha':24,'krishna':23,'ashmit':22}
s2=pd.Series(d1)
print("series using dictionary")
print(s2)
OUTPUT:
series from ndarray
0 23
1 34
2 45
3 67
4 78
dtype: int32
series using dictionary
niya 25
neha 24
krishna 23
ashmit 22
dtype: int64
2
,P2. Create a series to store the amount of sales made by a salesperson for the last
year(whole month)
a. display the sales amount which is greater than 10000
b. display the sales amount in the first four months
c. display the sales amount in the last four months
SOURCE CODE:
import pandas as pd
amount=[20000,10000,15000,22000,8000,5000,2000,22000,1000,3000,20000,10000]
months=['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
s1=pd.Series(data=amount,index=months)
print('sales amount>10000')
print(s1[s1>10000])
print('sales amount for the first four months')
print(s1.head(4)
print("sales amount for the last months")
print(s1.tail(4))
OUTPUT:
sales amount>10000
jan 20000
mar 15000
apr 22000
aug 22000
nov 20000
dtype: int64
sales amount for the first four months
jan 20000
feb 10000
mar 15000
apr 22000
dtype: int64
sales amount for the last months
sep 1000
oct 3000
nov 20000
dec 10000
dtype: int64
3
, P3. To 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,update it in the series.
SOURCE CODE:
import pandas as pd
D={'jhon':50000,'bala':60000,'anu':55000,'birundha':52000}
s=pd.Series(D)
print("employees salary before updating")
print(s)
print("\n")
opt=input("do you want to update the salary of the employee (y/n)?:")
if opt=='y':
name=input("enter the name of the employee:")
if name in s:
new_salary =float(input("enter the new salary:"))
s[name] = new_salary
print("\n salary updated succesfully")
print("\n employees salary after updating")
print(s)
else:
print("\n employee not found in the records.")
else:
print("\n thank you!!!")
4
SL.NO. DATE PROGRAM PG.NO REMARKS
A PANDAS SERIES
1 Create a Series from ndarray 2
and a dictionary of values
2 Series to display the amount of 3
sales made by salesperson
3 Updating existing values of 4
Series
4 Display Series objects using 6
iloc, loc and slicing
5 Attributes of Series objects 8
6 Mathematical operations on 9
Series
B PANDAS DATAFRAME
7 Create and display a 11
DataFrame
8 Accessing values of rows and 14
columns of a DataFrame
9 Inserting column and deleting 16
row from a DataFrame
10 Rename ,count, update and 18
replace operations on
DataFrame
11 Display the attributes of the 21
DataFrame
12 Iterations on DataFrame 22
13 Writing and reading 24
operations in a csv file
C MATPLOTLIB
14 Multiple line chart 25
15 Bar chart 26
16 Multiple bar chart from CSV 27
file
17 Histogram 28
D MYSQL 30
1
,P1. Create a series from ndarray and a dictionary of values
SOURCE CODE:
import pandas as pd
import numpy as np
si=pd.Series(np.array([23,34,45,67,78]))
print('series from ndarray')
print(si)
d1={'niya':25,'neha':24,'krishna':23,'ashmit':22}
s2=pd.Series(d1)
print("series using dictionary")
print(s2)
OUTPUT:
series from ndarray
0 23
1 34
2 45
3 67
4 78
dtype: int32
series using dictionary
niya 25
neha 24
krishna 23
ashmit 22
dtype: int64
2
,P2. Create a series to store the amount of sales made by a salesperson for the last
year(whole month)
a. display the sales amount which is greater than 10000
b. display the sales amount in the first four months
c. display the sales amount in the last four months
SOURCE CODE:
import pandas as pd
amount=[20000,10000,15000,22000,8000,5000,2000,22000,1000,3000,20000,10000]
months=['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
s1=pd.Series(data=amount,index=months)
print('sales amount>10000')
print(s1[s1>10000])
print('sales amount for the first four months')
print(s1.head(4)
print("sales amount for the last months")
print(s1.tail(4))
OUTPUT:
sales amount>10000
jan 20000
mar 15000
apr 22000
aug 22000
nov 20000
dtype: int64
sales amount for the first four months
jan 20000
feb 10000
mar 15000
apr 22000
dtype: int64
sales amount for the last months
sep 1000
oct 3000
nov 20000
dec 10000
dtype: int64
3
, P3. To 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,update it in the series.
SOURCE CODE:
import pandas as pd
D={'jhon':50000,'bala':60000,'anu':55000,'birundha':52000}
s=pd.Series(D)
print("employees salary before updating")
print(s)
print("\n")
opt=input("do you want to update the salary of the employee (y/n)?:")
if opt=='y':
name=input("enter the name of the employee:")
if name in s:
new_salary =float(input("enter the new salary:"))
s[name] = new_salary
print("\n salary updated succesfully")
print("\n employees salary after updating")
print(s)
else:
print("\n employee not found in the records.")
else:
print("\n thank you!!!")
4