0% found this document useful (0 votes)
0 views

Expt-16 python

Python code

Uploaded by

saadmunafshaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Expt-16 python

Python code

Uploaded by

saadmunafshaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

16
Q. WAP to display employee id number on X axis and their salaries on y-axis in the form of
a bar graph.
Program:
import matplotlib.pyplot as plt
# take employee ids and salaries for sales deptt.
x=[101,102,103,104,105]
y=[5000,6000, 4500,6000,8000]
# take employee ids and salaries for production deptt.
x1=[106,107,108,109,110]
y1=[10000,15000, 18000, 12000,8000]
# create bar graph
plt.bar(x,y,label="Clerks",color="blue")
plt.bar(x1,y1,label="Manager",color="yellow")
# set the label and legends
plt.xlabel("employee id")
plt.ylabel("salary")
plt.title("Company")
plt.legend()
#display
plt.show()

Output:
Q. WAP to display pie chart showing percentage of employees in a department of a company
Program:
import matplotlib.pyplot as plot
# take percentage of employees
slices=[30,20,30,20]
# department names
deptt=["purchase", "management","HR", "accounts"]
# colors of departments
cols=["yellow","green", "red","blue"]
# create piechart
plot.pie(slices, labels=deptt, colors=cols,
startangle=180,explode=(0,0.2,0,0),shadow=True,
autopct="%.1f%%")
plot.title(" RCOE")
plot.legend()
#display
plot.show()

Output:
Post Lab Question:
Q1. Write a program to display first five elements of a data frame?
Program:
import pandas as pd
# Create a Pandas DataFrame
data = {'Name': ['John', 'Sara', 'Mike', 'Julia', 'David'],
'Age': [25, 30, 35, 40, 45],
'City': ['New York', 'Chicago', 'San Francisco', 'Los
Angeles', 'Boston']}
df = pd.DataFrame(data)
# Display the first five elements of the DataFrame
print(df.head())
Output:

Q2. Write a program to display last five elements of a data frame?


Program:
import pandas as pd
# Create a sample data frame
data = {'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Emily',
'Frank'],
'Age': [25, 30, 35, 40, 45, 50],
'Salary': [50000, 60000, 70000, 80000, 90000, 100000]}
df = pd.DataFrame(data)
# Display the last five elements of the data frame
print(df.tail())
Output:

You might also like