Professional Documents
Culture Documents
Moocs Seminar File
Moocs Seminar File
Course : BCA
Section : G
Roll Number : 29
Problem Statement : Write a python program to use different techniques for filling the missing values.
Source Code :
import pandas as pd
data = {
'A': [1, 2, None, 4, 5],
'B': [3, None, 5, None, 7],
'C': [None, 2, 4, 6, None]
}
print("Original DataFrame:")
df = pd.DataFrame(data)
print(df)
print("\nImputed Data using Mean:")
df_mean=df.fillna(value=df['A'].mean())
print(df_mean)
print("\nImputed Data using Median:")
df_median=df.fillna(value=df['B'].median())
print(df_median)
print("\nImputed Data using Mode:")
df_mode=df.fillna(value=df['C'].mode()[0])
print(df_mode)
Original DataFrame:
A B C
0 1.0 3.0 NaN
1 2.0 NaN 2.0
2 NaN 5.0 4.0
3 4.0 NaN 6.0
4 5.0 7.0 NaN
Source Code :
import pandas as pd
from sklearn.datasets import make_classification
X, y = make_classification(
n_samples=1000,
n_features=10,
n_informative=5,
n_redundant=0,
random_state=42
)
df = pd.DataFrame(X, columns=[f'Feature_{i}' for i in range(1, 11)])
df['Target'] = y
df.to_csv('synthetic_dataset.csv', index=False)
print('Synthetic dataset generated and saved successfully!')
Output
Source Code :
matrix1 = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
matrix2 = [
[9, 8, 7],
[6, 5, 4],
[3, 2, 1]
]
result_matrix = add_matrices(matrix1, matrix2)
if result_matrix:
print("Resultant Matrix:")
for row in result_matrix:
print(row)
Output
Resultant Matrix:
[10, 10, 10]
[10, 10, 10]
[10, 10, 10]
Name : Opila Singh
Course : BCA
Section : G
Roll Number : 29
Problem Statement : Write a python program to multiply matrices.
Source Code :
Output
Resultant Matrix:
[30, 24, 18]
[84, 69, 54]
[138, 114, 90]
Name : Opila Singh
Course : BCA
Section : G
Roll Number : 29
Problem Statement : Write a python program to find the combinatorics of a given input number.
Source Code :
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
Output
Source Code :
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
Output
Source Code :
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
Output
Source Code :
def transpose_matrix(matrix):
return [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]
def print_matrix(matrix):
for row in matrix:
print(row)
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]
print("Original Matrix:")
print_matrix(matrix)
print("\nTranspose of the Matrix:")
transpose = transpose_matrix(matrix)
print_matrix(transpose)
Output
Original Matrix:
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Source Code :
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans