Skip to content

Commit

Permalink
import council level IMD data
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Apr 2, 2024
1 parent 2df9883 commit d478671
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions hub/management/commands/import_council_imd_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pandas as pd
from mysoc_dataset import get_dataset_url

from hub.import_utils import add_gss_codes, filter_authority_type
from hub.models import DataSet

from .base_importers import BaseImportFromDataFrameCommand, MultipleAreaTypesMixin


class Command(MultipleAreaTypesMixin, BaseImportFromDataFrameCommand):
help = "Import Council IMD data"

message = "Importing council IMD data"
cons_row = "gss_code"
area_types = ["STC", "DIS"]
uses_gss = True
do_not_convert = True

data_sets = {
"council_imd": {
"defaults": {
"source": "https://mysociety.github.io/composite_uk_imd/",
"source_label": "Data from ONS (England and Wales), NRS (Scotland), and NISRA (Northern Ireland), collated and standardised by mySociety.",
"name": "council_imd",
"description": "Deciles of deprivation, from 1 (most deprived) to 10 (least deprived). This uses a composite measure of deprivation (including income, employment, education, skills, health, crime, and housing) standardised across the countries of the UK.",
"label": "Index of Multiple Deprivation (IMD)",
"data_type": "integer",
"category": "place",
"source_type": "csv",
"table": "areadata",
"comparators": DataSet.numerical_comparators()[::-1],
"default_value": 5,
"unit_type": "percentage",
"unit_distribution": "people_in_area",
"is_public": True,
},
"col": "la-imd-pop-quintile",
}
}
package = {
"repo_name": "composite_uk_imd",
"package_name": "uk_index",
"version_name": "3.3.0",
"file_name": "la_imd.csv",
}

def __init__(self):
super().__init__()

url = get_dataset_url(
repo_name=self.package["repo_name"],
package_name=self.package["package_name"],
version_name=self.package["version_name"],
file_name=self.package["file_name"],
done_survey=True,
)

self.data_sets["council_imd"]["defaults"]["data_url"] = url

def get_dataframe(self):
df = pd.read_csv(self.data_sets["council_imd"]["defaults"]["data_url"])

df = add_gss_codes(df, "local-authority-code")
df = filter_authority_type(df, self.area_type, self.cons_row)
return df

def update_averages(self):
pass

0 comments on commit d478671

Please sign in to comment.