'why this agg() return only dtype[float64] without indexing
directors={}
meanscore={}
meanscore=df.groupby(['director_name']).agg([np.mean])["imdb_score"]
meanscore=meanscore.squeeze()
print(type(meanscore))#<class 'pandas.core.series.Series'>
print(meanscore)
print(meanscore.shape)#(117,) and if I try to call meanscore['director_name'] it will return errors
here are the result
<class 'pandas.core.series.Series'>
director_name
Akira Kurosawa 8.70
Alejandro Amenabar 8.10
Alejandro G. Inarritu 8.10
Alfred Hitchcock 8.50
Andrew Stanton 8.30
...
Victor Fleming 8.15
Vincent Paronnaud 8.00
Wes Anderson 8.10
Wolfgang Petersen 8.40
Woody Allen 8.10
Name: mean, Length: 117, dtype: float64
(117,)
how should I add the director_name as the index so the shape of the dictionary could be (117,2)
the squeeze was only because the wanted answer is a <class 'pandas.core.series.Series'> not <class 'pandas.core.frame.DataFrame'> neither a <class 'dict'>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
