Exp 1B Dav
Exp 1B Dav
1. Pandas
import pandas as pd
# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35]}
df = pd.DataFrame(data)
# Filter rows where Age > 25
filtered_df = df[df['Age'] > 25]
print(filtered_df)
OUTPUT:
2. NumPy
import numpy as np
# Create a NumPy array
arr = np.array([1, 2, 3, 4, 5])# Calculate the mean of the array
mean_value = np.mean(arr)
print(mean_value)
OUTPUT:
3. Matplotlib
import matplotlib.pyplot as plt
# Create a simple line plot
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.title("Line Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
OUTPUT:
4. Seaborn
import seaborn as sns
import pandas as pd
# Create a DataFrame
data = {'A': [1, 2, 3, 4], 'B': [2, 3, 4, 5]}
df = pd.DataFrame(data)# Create a scatter plot
sns.scatterplot(x='A', y='B', data=df)
OUTPUT:
5. Scikit-learn
from sklearn.linear_model import LinearRegression
import numpy as np
# Sample data
X = np.array([[1], [2], [3], [4]])
y = np.array([2.2, 4.3, 6.1, 8.0])
# Train a linear regression model
model = LinearRegression()
model.fit(X, y)
# Predict
prediction = model.predict([[5]])
print(prediction)
OUTPUT:
6. SciPy
from scipy.stats import norm# Calculate the probability density of a normal distribution
x=1
prob_density = norm.pdf(x, loc=0, scale=1)
print(prob_density)
OUTPUT:
7. Plotly
import plotly.express as px
# Create a bar chart
data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Score': [85, 90, 95]}
fig = px.bar(data, x='Name', y='Score', title='Student Scores')
fig.show()
OUTPUT:
8. Statsmodels
import statsmodels.api as sm
# Sample data
X = [1, 2, 3, 4]
y = [2.2, 4.3, 6.1, 8.0]
OUTPUT:
10. OpenCV
from google.colab.patches import cv2_imshow
!curl -o logo.png https://encrypted-tbn0.gstatic.com/images?
q=tbn:ANd9GcRW9h4fU35Nb2lGTCcT-GS1pVkWd5gqV0yegw&simport cv2
img = cv2.imread('logo.png', cv2.IMREAD_UNCHANGED)
cv2_imshow(img)
OUTPUT: