How is the Gini index used in Decision Trees and what does it represent?

I’m trying to understand the Gini index and how it’s used in decision trees. Can someone explain it to me in simple terms? How is it calculated, and what does it measure? Are there any advantages or disadvantages to using the Gini index over other impurity measures? And can you provide a code example in Python using the Iris dataset?

And here’s an example code snippet that you could include: