-
-
Save isauravmanitripathi/be5de70f18f6fd188b4dbddfeefbf29d to your computer and use it in GitHub Desktop.
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
acc_category = data[["category"]] | |
acc_category = acc_category.drop_duplicates() | |
acc_category = acc_category.reset_index(drop=True) | |
acc_category["id"] = acc_category.index | |
# relate tables with index | |
for i, row in data.iterrows(): | |
cat = data.at[i, "category"] | |
for j, row in acc_category.iterrows(): | |
if acc_category.at[j, "category"] == cat: | |
cat_id = acc_category.at[j, "id"] | |
data.at[i, "category_id"] = cat_id | |
data = data.drop(columns="category") | |
data = data.astype({"category_id":int, "num_injured":int}, errors="raise") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment