Expt-16 python
Expt-16 python
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: