python program (3)
python program (3)
AIM:
To Implement NumPy Operations with Arrays using python code.
ALGORITHM:
Step 1: START
Step 2: import the numpy Library.
Step 3: Initialize the numpy arrays to two different variables.
Step 4: Perform the numpy operations on the two arrays.
Step 5: Repeat the Step 4 until the user decides.
Setp 6: STOP
PROGRAM/SOURCE CODE:
# NUMPY OPERATIONS WITH ARRAYS
import numpy as np
a=np.array([[1,2],[4,5]])
b=np.array([[1,2],[4,5]])
while True:
print("1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product ,
6.Exponentiation ,7.Logarithm , 8.Natural logarithm , 9.Exit")
AIM:
To Implement working with Pandas data frame using python code.
ALGORITHM:
Step 1: Start the program.
Step 3: Import pandas with an aliased name as pd.
Step 4: Create a given list and assign it to variable data.
Step 5: Call the data Frame function (data), and assign it to variable t.
Step 6: Call the Print function to print the Pandas data frame(t).
Step 7: Stop the program.
PROGRAM/SOURCE CODE:
import pandas as pd data={"Name":["Ram","Subash","Raghul","Arun","Deepak"],"Age":[24,25,24,
26,25],"CGPA":[9.5,9.3,9.0,8.5,8.8]}
t=pd.DataFrame(data) t.index+=1
print(t)
OUTPUT:
2 Subash 25 9.3
3 Raghul 24 9.0
4 Arun 26 8.5
5 Deepak 25 8.8
RESULT:
Thus, the program to Implement working with Pandas data frame using Python code has been
executed successfully.
EX NO :3 BASIC PLOTS USING MATPLOTLIB
AIM:
To Implement Plotting the points for line graph using Matplotlib using python code.
ALGORITHM:
Step 3:Using plot() We can set the label as lineA and color of the line as red with x1 and y1 as co-
ordinates.
Step 6:Using plot() We can set the label as line B and color of the line as green with x2 and y2 as co-
ordinates.
Step 7: Using xlim() and ylim() we can set the points as 0 to 12 on x-axis and y- axis
. Step 8: show the x-axis and y-axis of the plot, show the title as Graph.
PROGRAM/SOURCE CODE:
import matplotlib.pyplot as mpl x1=[1,4,6,8]
y1=[2,5,8,9]
mpl.plot(x1,y1,label="line A",color="r") x2=[3,6,8,10]
y2=[2,4,8,9]
mpl.plot(x2,y2,label="line B",color="g") mpl.xlim(0,12)
mpl.ylim(0,12) mpl.xlabel("X-axis")
mpl.ylabel("Y-axis") mpl.title("Graph")
mpl.legend() mpl.show()
OUTPUT:
RESULT:
Thus, the program to Implement using Plotting the points using Matplotlib Python code has been executed
successfully.
3(b) CREATE A BAR CHART USING MATPLOTLIB
AIM:
To Implement a bar chart using Matplotlib using python code.
ALGORITHM:
Step 1: Store in x=[1,2,3,4,5]
Step 2: Store in y=[50,65,85,87,98]
Step 3: Store in text=["IBM","Amazon","Facebook","Microsoft","Google"] Step4: Store in
colors=["red","orange","yellow","blue","green"]
Step 5: Using xlim() and ylim() we can set the points as 0 to 6 on x-axis and 0 to 100 on y- axis
respectively.
Step 6: Using bar() we can create a bar graph with x,y with label as text and color=colors and line width of
the graph as 0.5.
Step 6: show the x-axis and y-axis of the plot as ‘Company' and 'Percentage', show the title as
Percentage Graph.
PROGRAM/SOURCE CODE:
import matplotlib.pyplot as mpl x=[1,2,3,4,5]
y=[50,65,85,87,98]
text=["IBM","Amazon","Facebook","Microsoft","Google"]
colors=["red","orange","yellow","blue","green"] mpl.xlim(0,6) mpl.ylim(0,100)
mpl.bar(x,y,tick_label=text,color=colors,linewidth=0.5) mpl.xlabel("Company")
mpl.ylabel("Percentage")
mpl.title("Percentage Graph") mpl.show()
OUTPUT:
RESULT:
Thus, the program to Implement a bar chart using Matplotlib using Python code has been
executed successfully.