Ankit Python
Ankit Python
Affiliated to:
Code:
# Importing required libraries import
numpy as np
from scipy import linalg
# Array addition b =
np.array([[5, 6], [7, 8]])
print("Array b:\n", b)
sum_array = a + b print("Sum of a
and b:\n", sum_array)
# Transpose print("Transpose
of a:\n", a.T)
# Basic statistics
print("Mean of a:", np.mean(a))
print("Standard Deviation of a:", np.std(a))
# SciPy Basics
print("\n----- SciPy -----")
# Linear Algebra: Solving system of linear equations
# Example: 2x + 3y = 8 and 3x + 4y = 11
A = np.array([[2, 3], [3, 4]])
b = np.array([8, 11])
Output
Program – 2
df = pd.DataFrame(data) print("Data
Table:\n", df)
Output
Program - 3
Code:
import pandas as pd
Code:
import pandas as pd
from scipy import stats
# Create DataFrame
df = pd.DataFrame(data)
Code:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame(data)
for _ in range(1000):
sample = df.sample(n=sample_size, replace=True)
sample_mean = sample['Price'].mean()
sample_means.append(sample_mean)
# Convert to Series
sample_means_series = pd.Series(sample_means)
import pandas as pd
Output
Program – 7
Code:
import pandas as pd
from scipy.stats import chisquare
df = pd.DataFrame(data)
print("Dataset:\n", df)
# Suppose we expect equal preference for all fruits (null hypothesis) expected_counts
= [total_responses / len(df)] * len(df)
if p_value < 0.05: print("Result: Reject the null hypothesis. Preferences are not
equally distributed.") else:
print("Result: Fail to reject the null hypothesis. Preferences are equally distributed.")
Output
Program – 8
Code:
import pandas as pd import
matplotlib.pyplot as plt
from scipy.stats import binom, norm
# PMF plot
plt.subplot(1, 3, 1)
plt.stem(df_pmf['Successes'], df_pmf['PMF'], basefmt=" ")
plt.title('PMF - Binomial Distribution') plt.xlabel('Number
of Successes') plt.ylabel('Probability')
plt.tight_layout()
plt.show()
Output
Program – 9
df = pd.DataFrame(data)
print("Sales Dataset:") print(df)
Output
Program – 10
Code:
import pandas as pd
from scipy import stats