Hslip17
Q1]
<?php // Given associative array $associativeArray = array("Sagar" => "31", "Vicky" => "41", "Leena" => "39", "Ramesh" => "40"); // a) Ascending order sort by Value asort($associativeArray); echo "a) Ascending order sort by Value: "; print_r($associativeArray); echo "<br>"; // b) Ascending order sort by Key ksort($associativeArray); echo "b) Ascending order sort by Key: "; print_r($associativeArray); echo "<br>"; // c) Descending order sorting by Value arsort($associativeArray); echo "c) Descending order sorting by Value: "; print_r($associativeArray); echo "<br>"; // d) Descending order sorting by Key krsort($associativeArray); echo "d) Descending order sorting by Key: "; print_r($associativeArray); ?>Q2]
A]
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
Load iris dataset
iris = load_iris()
Create a DataFrame using seaborn
iris_df = sns.load_dataset("iris")
Draw scatter plots to compare two features
plt.figure(figsize=(12, 5))
Scatter plot for sepal length and sepal width
plt.subplot(1, 2, 1)
sns.scatterplot(x="sepal_length", y="sepal_width", hue="species", data=iris_df)
plt.title('Scatter Plot: Sepal Length vs Sepal Width')
Scatter plot for petal length and petal width
plt.subplot(1, 2, 2)
sns.scatterplot(x="petal_length", y="petal_width", hue="species", data=iris_df)
plt.title('Scatter Plot: Petal Length vs Petal Width')
plt.tight_layout()
plt.show()
B]
import pandas as pd
Create a data frame with columns name, age, salary, and department
data = {'name': ['John', 'Alice', 'Bob', 'Charlie', 'David', 'Emma', 'Frank', 'Grace', 'Helen', 'Ivan'],
'age': [25, 28, 35, 40, 22, 30, 45, 29, 33, 38],
'salary': [50000, 60000, 75000, 55000, 80000, 70000, 90000, 62000, 68000, 80000],
'department': ['HR', 'IT', 'Finance', 'HR', 'IT', 'Finance', 'IT', 'Finance', 'HR', 'IT']}
df = pd.DataFrame(data)
Display the data frame
print("Data Frame:")
print(df)