Skip to content

Instantly share code, notes, and snippets.

@isauravmanitripathi
Created October 10, 2022 15:36
Show Gist options
  • Save isauravmanitripathi/be5de70f18f6fd188b4dbddfeefbf29d to your computer and use it in GitHub Desktop.
Save isauravmanitripathi/be5de70f18f6fd188b4dbddfeefbf29d to your computer and use it in GitHub Desktop.
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