-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvImport.py
More file actions
65 lines (48 loc) · 2.22 KB
/
Copy pathCsvImport.py
File metadata and controls
65 lines (48 loc) · 2.22 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
58
59
60
61
62
63
64
65
import pandas as pd
import matplotlib.pyplot as plt
# Load data from a CSV file
# Replace 'database.csv' with the path to your CSV file
#csv_file_path = r'C:\Users\RomeoNdlovu\OneDrive - IBM\Documents\TeleCom.csv'
csv_file_path = 'TeleCom.csv'
data = pd.read_csv(csv_file_path)
# Extract all numeric columns (ignoring non-numeric ones like strings)
numeric_data = data.select_dtypes(include=['number'])
# Create a list of all datasets
all_data = [numeric_data[col].dropna().tolist() for col in numeric_data.columns]
df = pd.DataFrame(data)
total_score = df["Salary"].sum()
print(f"The total Salary:R{total_score}")
max_tax = df["TaxDeduction"].max()
print(f"The maximum TaxDeduction:R{max_tax}")
mean_tax = df["TaxDeduction"].mean()
print(f"The mean TaxDeduction:R{mean_tax}")
groupby_gendercount = df.groupby('Gender')["Gender"].count()
print(f" Groupby Gender and show Count:{groupby_gendercount}")
groupby_gendersalary = df.groupby("Gender")["Salary"].mean()
print(f" Groupby Gender and their mean salary: R{groupby_gendersalary}")
groupby_gendersalarymax = df.groupby("Gender")["Salary"].max()
print(f" Groupby Gender and their max salary: R{groupby_gendersalarymax}")
groupby_gendersalarymin = df.groupby("Gender")["Salary"].min()
print(f" Groupby Gender and their min salary: R{groupby_gendersalarymin}")
groupby_gendertax = df.groupby("Gender")["TaxDeduction"].max()
print(f" Groupby Gender and their mean salary: R{groupby_gendertax}")
groupby_genderindepartment = df.groupby("Department")["Gender"].count()
print(f" Groupby Department and show Count:{groupby_genderindepartment}")
#mode_salary = df.mode()
#print(f"Mode of salary:{mode_salary}")
#describedata = df.describe()
#print(f"Show description:{describedata}")
'''plt.hist(df["Salary"])
plt.title("Salary Distribution")
plt.xlabel("Salary")
plt.ylabel("Frequency distribution")
plt.show()'''
#Bar charts oftern represent categorical data well
employeecount_bydepartment = df["Department"].value_counts()
plt.bar(employeecount_bydepartment.index,employeecount_bydepartment.values)
plt.title("No. of Employees in Department")
plt.xlabel("Deparment")
plt.ylabel("Employee Count")
plt.show()
corr = df["Salary"].corr(df["TaxDeduction"])
print(f"Correlation between Salary and Tax: {corr:.2f}")