0
In the Species column of the dataset, I have these flower species:
df['species'].unique()
output: array(['Iris-setosa', 'Iris-versicolor', 'Iris-virginica']
I need to average for each flower species using the variable sepal_width
of dataset:
df.sepal_width.head()
0 3.5
1 3.0
2 3.2
3 3.1
4 3.6
I only know how to make one by one using this code, for example:
especie_iris_setosa = df[df['species'] == 'Iris-setosa'] #traz todas as linhas que contenham a especie Iris-setosa
especie_iris_setosa['sepal_length'].mean()
output: 5.005999999999999
How can I make a loop that averages the sepal_width
for each species of flower in the column species
?
I think it would be something like this: for i in df.species:
but I don’t know how to.