-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
20 deletions.
There are no files selected for viewing
Binary file not shown.
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,28 @@ | ||
import pandas as pd | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from api.models import Country, District | ||
from api.logger import logger | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Population Data for District To run, python manage.py ingest_admin1_population Population.GO.Admin1.Matched.xlsx" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("filename", nargs="+", type=str) | ||
|
||
def handle(self, *args, **kwargs): | ||
logger.info("Updating population data for District") | ||
filename = kwargs["filename"][0] | ||
district_df = pd.read_excel(filename, usecols=['GO Names', 'ISO3', '2016']) | ||
district_df = district_df.rename(columns={'GO Names': 'District'}) | ||
count = 0 | ||
for index, row in district_df.iterrows(): | ||
district = District.objects.filter(name=row['District'].strip(), country__iso3=row['ISO3']).first() | ||
if district: | ||
count += 1 | ||
district.wb_population = row['2016'] | ||
district.wb_year = '2016' # Get this from excel file | ||
district.save(update_fields=['wb_population', 'wb_year']) | ||
logger.info(f'Updated population data for {count} district') |
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