Missing some part of the groupby() syntax /u/MiracleNamedHope Python Education

Here is the code:

”’

planets = pd.DataFrame(data) P = planets.groupby(['type', 'magnetic_field']).agg(['mean', 'max']) print(P) 

”’

It errors out to this:

TypeError: agg function failed [how->mean,dtype->object]

I interpret this to be telling me that I’m trying to take the mean of a non-numeric type. So I’ve tried to insert this: (numeric_only=True)

But I don’t think I inserted that at the correct spot. Any pointers here on how the syntax would work to get the mean and max for that magnetic_field column? Thanks for your time!

submitted by /u/MiracleNamedHope
[link] [comments]

​r/learnpython Here is the code: ”’ planets = pd.DataFrame(data) P = planets.groupby([‘type’, ‘magnetic_field’]).agg([‘mean’, ‘max’]) print(P) ”’ It errors out to this: TypeError: agg function failed [how->mean,dtype->object] I interpret this to be telling me that I’m trying to take the mean of a non-numeric type. So I’ve tried to insert this: (numeric_only=True) But I don’t think I inserted that at the correct spot. Any pointers here on how the syntax would work to get the mean and max for that magnetic_field column? Thanks for your time! submitted by /u/MiracleNamedHope [link] [comments] 

Here is the code:

”’

planets = pd.DataFrame(data) P = planets.groupby(['type', 'magnetic_field']).agg(['mean', 'max']) print(P) 

”’

It errors out to this:

TypeError: agg function failed [how->mean,dtype->object]

I interpret this to be telling me that I’m trying to take the mean of a non-numeric type. So I’ve tried to insert this: (numeric_only=True)

But I don’t think I inserted that at the correct spot. Any pointers here on how the syntax would work to get the mean and max for that magnetic_field column? Thanks for your time!

submitted by /u/MiracleNamedHope
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *