Data Analysis with SciPy (original) (raw)

Last Updated : 15 Jun, 2026

SciPy (Scientific Python) is an open-source Python library for scientific computing and data analysis. Built on top of NumPy, it provides tools for statistics, optimization, signal processing and other mathematical operations.

1. Importing Required Libraries

import numpy as np import pandas as pd

`

2. Measures of Central Tendency Using SciPy

from scipy import stats import numpy as np

data = [10, 20, 30, 40, 50]

print("Mean:", np.mean(data)) print("Median:", np.median(data)) print("Mode:", stats.mode(data))

`

**Output:

output

Output

3. Probability Distribution Analysis Using SciPy

Probability distributions describe how data values are distributed.

from scipy.stats import norm

probability = norm.cdf(85, loc=70, scale=10)

print("Probability:", probability)

`

**Output:

Probability: 0.9331

4. Hypothesis Testing

Hypothesis testing helps determine whether a statistical claim is supported by data. SciPy provides functions for t-tests, chi-square tests and other statistical tests.

from scipy import stats

data = [22, 25, 19, 24, 28, 30]

t_stat, p_value = stats.ttest_1samp(data, 25)

print("T-Statistic:", t_stat) print("P-Value:", p_value)

`

**Output:

T-Statistic: -0.204

P-Value: 0.845

5. Correlation Analysis

Correlation measures the strength and direction of the relationship between two variables.

from scipy.stats import pearsonr

x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10]

corr, p_value = pearsonr(x, y)

print("Correlation:", corr)

`

**Output:

Correlation: 1.0

6. Linear Algebra Operations

SciPy provides efficient functions for matrix operations and solving linear equations.

from scipy import linalg

A = [[3, 2], [1, 2]] B = [5, 5]

solution = linalg.solve(A, B)

print(solution)

`

**Output:

[0. 2.5]

7. Optimization Using SciPy

Optimization is used to find the best solution to a problem by minimizing or maximizing a function.

from scipy.optimize import minimize

def objective(x): return x**2 + 4

result = minimize(objective, x0=5)

print(result.x)

`

**Output:

[-2.62955131e-08]

Download full code from here

Advantages

Limitations