Advance Python Lab Solution
Advance Python Lab Solution
Q
method.
Ans:-
import numpy as np
data = np.array([1, 2, 3, 4, 5, 5, 6, 7, 8, 9])
# Mean
mean = np.mean(data)
# Median
median = np.median(data)
# Mode
mode = np.argmax(np.bincount(data))
print("Mean:", mean)
print("Median:", median)
print("Mode:", mode)
OUTPUT:-
Mean: 5.0
Median: 5.0
Mode: 5
( a) . Matplotlib Line
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y = np.sin(x)
plt.plot(x, y)
plt.title('Matplotlib Line Example')
plt.xlabel('x')
lt.ylabel('y')
p
plt.show()
lt.bar(x, y)
p
plt.title('Matplotlib Bar Example')
plt.xlabel('Categories')
plt.ylabel('Values')
plt.show()
= np.random.rand(50)
x
y = np.random.rand(50)
colors = np.random.rand(50)
sizes = 1000 * np.random.rand(50)
lt.hist(data, bins=30)
p
plt.title('Matplotlib Histogram Example')
lt.xlabel('Value')
p
plt.ylabel('Frequency')
plt.show()
f = pd.DataFrame(data)
d
new_data = {'Name': 'Mike', 'Age': 45, 'Gender': 'M'}
df = df.append(new_data, ignore_index=True)
df_cleaned = df.dropna()
print(df_cleaned)
OUTPUT:-
Name Age Gender
0 John 25 M
1 Anna 30 F
2 Peter 35 M
3 Linda 40 F
4 Mike 45 M