-
Notifications
You must be signed in to change notification settings - Fork 1
Albania fix func1 and mapping for admin2_new #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
80567d8
84dc1da
03cd7a4
c381f60
64400b7
ab208bb
8eff351
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,10 @@ | |
| raw_microdata_csv_dir = prepare_raw_microdata_csv_dir(COUNTRY) | ||
| ADMIN2_PAD_LENGTH = 3 | ||
|
|
||
| # admin2 to admin2_new mapping | ||
| mapping = pd.read_csv('./mapping.csv') | ||
| mapping = mapping[['admin2', 'admin2_new', 'county']].rename(columns={'admin2': 'admin2_tmp'}).astype({'admin2_new': 'str'}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this mapping going to change in the future? I assume this is a one time adjustment to get the new admin regions to conform the old ones but if not, could we check if the admin2 is a 2 digit code or a 3 digit code? In some cases I noticed that we have correct length padding but in other cases the leading zeros are not present. This may not be relevant here though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When merging mapping df with the main dataframe, I temporarily converted the admin2 code into integer, so that we could ignore the padding length inconsistencies. So I think for our case, we don't have to worry about the paddings. |
||
|
|
||
| col_format_map_7 = { | ||
| "admin2": r"\d{3}", | ||
| "admin3": r"\d{2}", | ||
|
|
@@ -189,6 +193,8 @@ def format_float(x): | |
|
|
||
| df = pd.concat([df_7, df_3], ignore_index=True) | ||
| df['counties'] = df.admin2.map(lambda x: map_to_region(pad_left(str(x).split('.')[0], length=ADMIN2_PAD_LENGTH))) | ||
| df['admin2_tmp'] = df.admin2.astype(int) | ||
| df = df.merge(mapping, on='admin2_tmp', how='left').drop(columns=['admin2_tmp']) | ||
| outfile = f'{raw_microdata_csv_dir}/{year}.csv' | ||
| df.to_csv(outfile, index=False) | ||
|
|
||
|
|
@@ -217,5 +223,11 @@ def format_float(x): | |
|
|
||
| df = pd.concat([df_7_rev, df_46655], ignore_index=True) | ||
| df['year'] = year | ||
| df['admin2_tmp'] = df.admin2.astype(int) | ||
| df = df.merge(mapping, on='admin2_tmp', how='left').drop(columns=['admin2_tmp']) | ||
| outfile = f'{raw_microdata_csv_dir}/{year}_rev.csv' | ||
| df.to_csv(outfile, index=False) | ||
|
|
||
| # COMMAND ---------- | ||
|
|
||
| df | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bhupatiraju
Thank you so much for taking a look!
Could you try running this scrip here to confirm that the files can now be loaded using the relative path in the project?
Could you also make sure that you're in the "Repo/{your email address}/{repo_name} folder when testing?