-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAverage family Income of Students.py
66 lines (35 loc) · 1.26 KB
/
Average family Income of Students.py
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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
# In[2]:
readxl=pd.read_excel('Data analyst Data.xlsx')
# In[3]:
df=pd.DataFrame(readxl)
# In[18]:
student=df[df['Designation'].str.strip().str.lower().str.contains('student')].copy()
student.dropna()
print(student['Family Income'].unique())
# In[19]:
std_inc1=student[student['Family Income']=='0-2 Lakh']
std_inc2=student[student['Family Income']=='2-5 Lakh']
std_inc3=student[student['Family Income']=='5-7 Lakh']
std_inc4=student[student['Family Income']=='7 Lakh+']
std1len=len(std_inc1)
std2len=len(std_inc2)
std3len=len(std_inc3)
std4len=len(std_inc4)
# In[21]:
income_range=["0-200000","200000-500000","500000-700000","700000+"]
frequencies=[std1len,std2len,std3len,std4len]
def calculate_midpoint(range_str):
if "+" in range_str:
return int(income_range[income_range.index(range_str) - 1].split('-')[1])
else:
start, end = map(int, range_str.split('-'))
return (start + end) / 2
weighted_sum = sum(f * calculate_midpoint(range_str) for f, range_str in zip(frequencies, income_range))
total_data_points = sum(frequencies)
overall_average_salary = weighted_sum / total_data_points
print("Overall average family income:", overall_average_salary)
# In[ ]: