-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATASET: Christian aid campaign organisers
- Loading branch information
1 parent
99e7a05
commit b8a3aa7
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
hub/management/commands/import_christian_aid_campaign_organisers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from django.conf import settings | ||
|
||
import pandas as pd | ||
|
||
from hub.models import AreaData, DataSet | ||
|
||
from .base_importers import BaseImportFromDataFrameCommand | ||
|
||
|
||
class Command(BaseImportFromDataFrameCommand): | ||
help = ( | ||
"Import data about number of Christian Aid campaign organisers per constituency" | ||
) | ||
|
||
data_file = ( | ||
settings.BASE_DIR | ||
/ "data" | ||
/ "Christian Aid climate campaign organisers - Data.csv" | ||
) | ||
cons_row = "Constituency" | ||
message = "Importing Christian Aid climate campaign organisers data" | ||
uses_gss = False | ||
|
||
defaults = { | ||
"data_type": "integer", | ||
"category": "movement", | ||
"subcategory": "supporters_and_activists", | ||
"description": "Number of Christian Aid campaign organisers per constituency.", | ||
"release_date": "February 2023", | ||
"source_label": "Data from Christian Aid.", | ||
"source": "https://www.christianaid.org.uk/", | ||
"source_type": "google sheet", | ||
"table": "areadata", | ||
"default_value": 1, | ||
"data_url": "", | ||
"unit_type": "raw", | ||
"unit_distribution": "people_in_area", | ||
"comparators": DataSet.numerical_comparators(), | ||
} | ||
|
||
data_sets = { | ||
"constituency_foe_activists_count": { | ||
"defaults": defaults, | ||
"col": "organisers", | ||
}, | ||
} | ||
|
||
def get_dataframe(self): | ||
df = pd.read_csv(self.data_file) | ||
df = ( | ||
df.groupby("Constituency") | ||
.count() | ||
.reset_index() | ||
.rename(columns={"Postcode": "organisers"}) | ||
) | ||
return df | ||
|
||
def get_label(self, defaults): | ||
return f"Number of Christian Aid climate campaign organisers" | ||
|
||
def delete_data(self): | ||
AreaData.objects.filter(data_type__in=self.data_types.values()).delete() |