batch1 ds
batch1 ds
1. Write a NumPy program to search the index of a given array in another given array.
Program:
import numpy as np
if result[0].size > 0:
return result[0][0]
else:
return -1
output
Index of sub_array: 1
Program:
import numpy as np
output:
[['a' '1']
['b' '2']
['c' '3']]
3..Write a Pandas program to select all columns, except one given column
in a DataFrame.
Program:
import pandas as pd
data = {
'A': [1, 2, 3],
'B': [4, 5, 6],
'C': [7, 8, 9],
}
df = pd.DataFrame(data)
column_to_exclude = 'B'
df_selected = df.drop(columns=[column_to_exclude])
print(df_selected)
output:
A C
0 1 7
1 2 8
2 3 9
4 . Write a Pandas program to get first n records of a DataFrame.
Program:
import pandas as pd
data = {
'A': [1, 2, 3, 4, 5],
'B': [6, 7, 8, 9, 10],
'C': [11, 12, 13, 14, 15],
}
df = pd.DataFrame(data)
n=3
first_n_records = df.head(n)
print(first_n_records)
output:
A B C
0 1 6 11
1 2 7 12
2 3 8 13
5. Apply and explore various plotting functions on UCI data set for performing the
following:
a) Correlation and scatter plots
b) Histograms
c) Three-dimensional plotting.
Program:
# 2. Histograms
data.iloc[:, :-1].hist(bins=15, figsize=(10, 8), color='skyblue', edgecolor='black')
plt.suptitle("Histograms of Features")
plt.show()
# 3. Three-dimensional Plotting
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# Scatter plot in 3D
scatter = ax.scatter(
data.iloc[:, 0], # First feature
data.iloc[:, 1], # Second feature
data.iloc[:, 2], # Third feature
c=data['species'].map({'setosa': 'r', 'versicolor': 'g', 'virginica': 'b'}),
label=data['species'],
alpha=0.7
)
output:
6. Apply and explore various plotting functions on UCI data set for performing the
following:
a) Normal values
b) Density and contour plots
c) Three-dimensional plotting
Program:
# Import necessary libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from mpl_toolkits.mplot3d import Axes3D
from scipy.stats import zscore
output:
7. Use the diabetes data set from UCI data set for performing the following:
Apply Bivariate analysis:
• Multiple Regression analysis
8. Use the diabetes data set from UCI data set for performing the following:
Apply Bivariate analysis:
• Linear and logistic regression modeling
9. Use the diabetes data set from UCI data set for performing the following:
Apply Univariate analysis:
• Frequency
• Mean,
• Median,
• Mode,
• Variance
• Standard Deviation
• Skewness and Kurtosis
10. Reading data from text files, Excel and the web and exploring various
commands for doing descriptive analytics on the Iris data set
output:
12. Write a Pandas program to select the rows where the number of attempts in
the examination is
greater than 2.
Program:
output:
Rows where the number of attempts is greater than 2:
Name Score Attempts Grade
1 Bob 78 3 B
3 David 65 4 C
4 Eva 88 3 B
Program:
# Import the pandas library
import pandas as pd
# Create a DataFrame from the dictionary with the specified index labels
df = pd.DataFrame(data, index=index_labels)
output:
DataFrame:
Name Age City Score
A Alice 25 New York 85
B Bob 30 Los Angeles 90
C Charlie 35 Chicago 88
D David 40 Houston 92
14.
output:
Original array: [1 2 3 4 5]
Array converted to float type: [1. 2. 3. 4. 5.]
[ ]:
1
output:
Empty array:
[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]
output:
Array from List: [1 2 3 4 5]
Array from Tuple: [ 6 7 8 9 10]
d. Write a NumPy program to find the real and imaginary parts of an array of complex
numbers
Program:
import numpy as np
output:
Original Complex Array: [ 3.+4.j 1.+2.j 5.-6.j -2.+3.j]
Real Part: [ 3. 1. 5. -2.]
Imaginary Part: [ 4. 2. -6. 3.]
15..
# Create a 2D array
original_array = np.array([[1, 2, 3], [4, 5, 6]])
# Create an array
original_array = np.array([1, 2, 3, 4])
# Values to append
values_to_append = [5, 6, 7]