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

python program (3)

The document outlines three exercises demonstrating the use of Python libraries NumPy, Pandas, and Matplotlib. Each exercise includes an aim, algorithm, source code, output, and a result confirming successful execution. The exercises cover operations with NumPy arrays, creating a Pandas DataFrame, and generating plots and bar charts using Matplotlib.

Uploaded by

raja sp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

python program (3)

The document outlines three exercises demonstrating the use of Python libraries NumPy, Pandas, and Matplotlib. Each exercise includes an aim, algorithm, source code, output, and a result confirming successful execution. The exercises cover operations with NumPy arrays, creating a Pandas DataFrame, and generating plots and bar charts using Matplotlib.

Uploaded by

raja sp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

EX NO :1 WORKING WITH NUMPY ARRAYS

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")

n=int(input("Enter the option number : ")) if not


n<1 and not n>8:
if n==1:
c=np.add(a,b)
print("Sum\n",c)
print("\n") elif
n==2:
d=np.subtract(a,b)
print("Difference\n",d)
print("\n")
elif n==3: e=np.multiply(a,b)
print("Product\n",e) print("\
n")
elif n==4: f=np.divide(a,b)
print("Remainder\n",f)
print("\n")
elif n==5:
g=np.dot(a,b)
print("Dot product\n",g)
print("\n")
elif n==6:
h,i=np.exp(a),np.exp(b)
print("Exponentiation for array a : \n",h)
print("Exponentiation for array b : \n",i)
print("\n")
elif n==7:
l,m=np.log(a),np.log(b)
print("Logarithm for array a : \n",l)
print("Logarithm for array b : \n",m)
print("\n")
elif n==8: x,y=np.log10(a),np.log10(b)
print("Natural logarithm for array a : \n",x)
print("Natural logarithm for array b : \n",y)
print("\n")
elif
n==9:
break
else:
print("No such option exist,please enter existing options.\n")
OUTPUT:
1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation , 7.Logarithm ,
8.Natural logarithm , 9.Exit
Enter the option number : 1
Sum
[[ 2 4]
[ 8 10]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation , 7.Logarithm ,


8.Natural logarithm , 9.Exit
Enter the option number : 8
Natural logarithm for array a :
[[0. 0.30103 ]
[0.60205999 0.69897 ]]
Natural logarithm for array b :
[[0. 0.30103 ]
[0.60205999 0.69897 ]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation , 7.Logarithm ,


8.Natural logarithm , 9.Exit
Enter the option number : 3
Product
[[ 1 4]
[16 25]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation , 7.Logarithm ,


8.Natural logarithm ,
9.Exit Enter the option
number : 5 Dot product
[[ 9 12]
[24 33]]

1.Add , 2.Subtract , 3.Multiply , 4.Divide , 5.Dot product , 6.Exponentiation , 7.Logarithm ,


8.Natural logarithm , 9.Exit
Enter the option number : 9
>>>
RESULT:
Thus, the program to Implement NumPy Operations with Arrays using Python code
has been executed successfully.
EX NO :2 WORKING WITH PANDAS DATA FRAMES

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:

Name Age CGPA


1 Ram 24 9.5

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

3(a) PLOTTING THE POINTS USING MATPLOTLIB

AIM:
To Implement Plotting the points for line graph using Matplotlib using python code.

ALGORITHM:

Step 1: Store in x1=[1,4,6,8]

Step 2: Store in y1=[2,5,8,9]

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 4: Store in x2=[3,6,8,10]

Step 5: Store in y2=[2,4,8,9]

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy