I have a dataset which is fairly large (around 50000 entries) structured in the following way.
| state id | Dist id | Name |
|---|---|---|
| 32 | 0 | Jammu & Kashmir |
| 32 | 0 | Jammu & Kashmir |
| 32 | 0 | Jammu & Kashmir |
| 32 | 1 | Kupwara |
| 32 | 1 | Kupwara |
| 32 | 4 | Badgam |
| 32 | 4 | Badgam |
| 32 | 14 | Kathua |
| 32 | 14 | Kathua |
| 12 | 0 | Arunachal Pradesh |
| 12 | 0 | Arunachal Pradesh |
| 12 | 10 | Dibang Valley |
| 12 | 10 | Dibang Valley |
To explain this, the state id identifies the state and if the district id happens to be 0 for that particular row, it means the value (which is there in other columns) is for the entire state. However, if the district id happens to be any other number other than 0, the value is for that particular district (which is within the state, given by the state id)
My aim is to get two more columns to this dataset, 'state_name' and 'district_name' such that state_name is filled by all the Name column which has Dist id = 0 and the similar state id. The second column district_name will be filled by the district name.
The expected output is the following table:
| state id | Dist id | Name | state_name | district_name |
|---|---|---|---|---|
| 32 | 0 | Jammu & Kashmir | Jammu & Kashmir | - |
| 32 | 0 | Jammu & Kashmir | Jammu & Kashmir | - |
| 32 | 0 | Jammu & Kashmir | Jammu & Kashmir | - |
| 32 | 1 | Kupwara | Jammu & Kashmir | Kupwara |
| 32 | 1 | Kupwara | Jammu & Kashmir | Kupwara |
| 32 | 4 | Badgam | Jammu & Kashmir | Badgam |
| 32 | 4 | Badgam | Jammu & Kashmir | Badgam |
| 32 | 14 | Kathua | Jammu & Kashmir | Kathua |
| 32 | 14 | Kathua | Jammu & Kashmir | Kathua |
| 12 | 0 | Arunachal Pradesh | Arunachal Pradesh | - |
| 12 | 0 | Arunachal Pradesh | Arunachal Pradesh | - |
| 12 | 10 | Dibang Valley | Arunachal Pradesh | Dibang Valley |
| 12 | 10 | Dibang Valley | Arunachal Pradesh | Dibang Valley |
How do I go about this?

