I have a dataset composed of 3 differents groups A, B, C :
df = pd.DataFrame([[1, "A", "A"], [2, "B", "B"], [3, "A", "A"], [4, "B", "B"], [5, "C", "C"], [6, "C", "C"],
[7, "A", "A"], [8, "B", "B"], [9, "C", "C"]],
columns=["Index", "Group", "Cluster"])
For each group I determine some cluster and I would like to replace the cluster column by the value of the cluster. I have one list for each cluster
listA = [0, 1, 1]
listB = [1, 0, 1]
listC = [0, 0, 1]
I would like to have something like that at the end :
| Index | Group | Cluster |
|---|---|---|
| 1 | A | 0 |
| 2 | B | 1 |
| 3 | A | 1 |
| 4 | B | 0 |
| 5 | C | 0 |
| 6 | C | 0 |
| 7 | A | 1 |
| 8 | B | 1 |
| 9 | C | 1 |