-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22073281.py
More file actions
57 lines (41 loc) · 1.62 KB
/
22073281.py
File metadata and controls
57 lines (41 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 4 16:24:15 2024
@author: sam jacob
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm, skew, kurtosis
data = pd.read_csv("data1.csv", names=['Salary'])
# Plot the histogram
plt.hist(data['Salary'], bins=30, density=True, label='PDF',alpha=0.7, color='#1f77b4', edgecolor='black')
# Fit a normal distribution to the data
mu, std = norm.fit(data['Salary'])
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mu, std)
# Plot the PDF as a black line
plt.plot(x, p, 'k', linewidth=2, label='Normal distribution fit')
# Calculate and print the mean annual salary (W)
mean_salary = np.mean(data['Salary'])
plt.axvline(mean_salary, color='red', linestyle='dashed', linewidth=2, label=f'Mean Salary ($W$): {mean_salary:.2f}')
# Calculate the value 'X', which is the 67th percentile of the salary data, and plot a vertical line at this value.
X = np.percentile(data['Salary'], 67) # 100% - 33% = 67%
plt.axvline(X, color='purple', linestyle='dashed', linewidth=2, label=f'X: {X:.2f}')
# Add labels, title, and legend
plt.xlabel('Annual Salary (Euros)')
plt.ylabel('Probability Density')
plt.title('Distribution of Annual Salaries')
#set x-axis and y-axis limit start from 0
plt.xlim(0,xmax)
plt.ylim(0,plt.ylim()[1])
plt.legend()
# Show the plot
plt.show()
# Calculate skewness and kurtosis
salary_skewness = skew(data['Salary'])
salary_kurtosis = kurtosis(data['Salary'])
# Print skewness and kurtosis
print(f"Skewness of the salary distribution: {salary_skewness}")
print(f"Kurtosis of the salary distribution: {salary_kurtosis}")