ElvarThorS commited on
Commit
608194a
·
1 Parent(s): c84bcf7

Income decile fethcing

Browse files
data_processing/age_distribution_by_id.py CHANGED
@@ -34,6 +34,7 @@ def get_age_distribution(years, smsv_ids, filename):
34
 
35
  if row_smsv_id not in age_distributions:
36
  age_distributions[row_smsv_id] = {}
 
37
  if row_year not in age_distributions[row_smsv_id]:
38
  age_distributions[row_smsv_id][row_year] = {}
39
 
@@ -47,7 +48,8 @@ if __name__ == '__main__':
47
  # Example usage:
48
  filename = os.path.join('given_data', 'ibuafjoldi.csv')
49
  smsv_ids_to_find = ['0103', '2903', '4002'] # List of desired smsv_ids
50
- age_dist = get_age_distribution([2017, 2024],smsv_ids_to_find, filename)
 
51
 
52
  for smsv_id, distributions in age_dist.items():
53
  print(f"Age Distribution for SMSV ID: {smsv_id}")
 
34
 
35
  if row_smsv_id not in age_distributions:
36
  age_distributions[row_smsv_id] = {}
37
+
38
  if row_year not in age_distributions[row_smsv_id]:
39
  age_distributions[row_smsv_id][row_year] = {}
40
 
 
48
  # Example usage:
49
  filename = os.path.join('given_data', 'ibuafjoldi.csv')
50
  smsv_ids_to_find = ['0103', '2903', '4002'] # List of desired smsv_ids
51
+ years = [2017, 2024]
52
+ age_dist = get_age_distribution(years, smsv_ids_to_find, filename)
53
 
54
  for smsv_id, distributions in age_dist.items():
55
  print(f"Age Distribution for SMSV ID: {smsv_id}")
data_processing/income_decile_by_id.py CHANGED
@@ -1,4 +1,5 @@
1
  import csv
 
2
 
3
  def open_file(filename):
4
  try:
@@ -14,17 +15,42 @@ def open_file(filename):
14
  return []
15
 
16
  def get_income_decile(years, smsv_ids, filename):
17
- income_deciles = {smsv_ids: {year: {} for year in years} for smsv_id in smsv_ids} # Initialize output dict
18
  csv_data = open_file(filename)
19
 
20
- if csv_data(): # Check if data is empty
21
  header = csv_data[0] # Extract header for column indexing
22
  smsv_id_index = header.index('smasvaedi')
23
  decile_index = header.index('tekjutiund')
24
-
25
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  if __name__ == '__main__':
28
  # Example usage:
29
- filename = './given_data/ibuafjoldi.csv'
30
- smsv_ids_to_find = ['0103', '2903', '4002'] # List of desired smsv_ids
 
 
 
 
 
 
 
 
 
1
  import csv
2
+ import os
3
 
4
  def open_file(filename):
5
  try:
 
15
  return []
16
 
17
  def get_income_decile(years, smsv_ids, filename):
18
+ income_deciles = {smsv_id: {year: {} for year in years} for smsv_id in smsv_ids} # Initialize output dict
19
  csv_data = open_file(filename)
20
 
21
+ if csv_data: # Check if data is empty
22
  header = csv_data[0] # Extract header for column indexing
23
  smsv_id_index = header.index('smasvaedi')
24
  decile_index = header.index('tekjutiund')
25
+ population_index = header.index('fjoldi')
26
+ year_index = header.index('ar')
27
+
28
+ for row in csv_data[1:]: # Skip header
29
+ row_smsv_id = row[smsv_id_index]
30
+ row_year = int(row[year_index])
31
+ if row_smsv_id in smsv_ids and row_year in years:
32
+ decile_group = row[decile_index]
33
+ population = int(row[population_index])
34
+
35
+ if row_smsv_id not in income_deciles:
36
+ income_deciles[row_smsv_id] = {}
37
+
38
+ if row_year not in income_deciles[row_smsv_id]:
39
+ income_deciles[row_smsv_id][row_year] = {}
40
+
41
+ if decile_group not in income_deciles[row_smsv_id][row_year]:
42
+ income_deciles[row_smsv_id][row_year][int(decile_group)] = population
43
+ return income_deciles
44
 
45
  if __name__ == '__main__':
46
  # Example usage:
47
+ filename = os.path.join('given_data', 'tekjutiundir.csv')
48
+ smsv_ids_to_find = ['0103', '2903', '4002'] # List of desired smsv_ids
49
+ years = [2017, 2024]
50
+ income_decile = get_income_decile(years, smsv_ids_to_find, filename)
51
+
52
+ for smsv_id, deciles in income_decile.items():
53
+ print(f"Income Deciles for SMSV ID: {smsv_id}")
54
+ for decile, population in deciles.items():
55
+ print(f" - {decile}: {population}")
56
+ print()