I have a dataframe of covid information from different regions in UK. I want to add a column and give every region an ID,( for example I want Scotland to be 1, Wales 2,...) the data frame looks like:
| Name | Date |
|---|---|
| Scotland | 1/2020 |
| Scotland | 2/2020 |
| Scotland | 3/2020 |
| Scotland | 4/2020 |
| Wales | 1/2020 |
| Wales | 2/2020 |
| Northern Ireland | 2/2020 |
| Northern Ireland | 3/2020 |
| ... | ... |
I have tried:
UK_df['ID'] = 0
for index, region in enumerate (UK_regions):
UK_df[UK_df.Name == region][x] = index
but it gave an error. this is what I want:
| ID | Name | Date |
|---|---|---|
| 1 | Scotland | 1/2020 |
| 1 | Scotland | 2/2020 |
| 1 | Scotland | 3/2020 |
| 1 | Scotland | 4/2020 |
| 2 | Wales | 1/2020 |
| 2 | Wales | 2/2020 |
| 3 | Northern Ireland | 2/2020 |
| 3 | Northern Ireland | 3/2020 |
| 4 | ... | ... |