0% found this document useful (0 votes)
4 views2 pages

Man Avg

Python solution

Uploaded by

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

Man Avg

Python solution

Uploaded by

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

5 Write a python program to compute sum of Manhattan distance

between all pairs of points.


[25]: from scipy.spatial import distance
# two points
a = (2, 4, 4, 6)
b = (5, 5, 7, 8)
# mahattan distance b/w a and b
d = distance.cityblock(a, b)
# display the result
print("Manhattan Distance is : ")
print(d)

Manhattan Distance is :
9

6 Write a NumPy program to compute the histogram of nums


against the bins.
[32]: import numpy as np
import matplotlib.pyplot as plt
nums = np.array([0.5, 0.7, 1.0, 1.2, 1.3, 2.1])
bins = np.array([0, 1, 2, 3])
print("nums : ",nums)
print("bins : ",bins)
print("Result : ",np.histogram(nums, bins))
plt.hist(nums,bins=bins)
plt.xlabel("X-axis")
plt.ylabel("y-axis")
plt.show()

nums : [0.5 0.7 1. 1.2 1.3 2.1]


bins : [0 1 2 3]
Result : (array([2, 3, 1]), array([0, 1, 2, 3]))

3
7 Create a dataframe for students’ information such name, grad-
uation percentage and age.Display average age of students, av-
erage of graduation percentage. And, also describe all basic
statistics of data. (Hint: use describe()).
[40]: import pandas as pd
import numpy as np
exam_data = {'name' : ['Akash','Rohan','Priyanka','Pooja','Rushikesh'],
'percentage' : [58,80,75,60,90],
'age' : [25,23,19,21,24]}
df = pd.DataFrame(exam_data)
print(df)
print("Average Age of Students : ");
print(df['age'].mean())
print("Average Percentage of Students : ");
print(df['percentage'].mean())
print("Basic Statistics of Data : ");
print(df.describe())

name percentage age


0 Akash 58 25
1 Rohan 80 23
2 Priyanka 75 19

You might also like