Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Introduction to pandas Exploring pandas Exploration Methods

Nicole Buckenwolf
Nicole Buckenwolf
8,721 Points

Stumped by pandas update this time - help with groupby

Whoops not sure if it included the lesson - linking just in case, this question is about Exploration Methods in Introduction to Pandas.

Hi all, google isn't helping me as much this time so I'm hoping someone can chime in.

When I try to run the aggregations like

users.mean()

I get a TypeError. I did locate the pandas documentation where it says this has changed since the course was made. Using this I was able to figure out how to aggregate individual columns, like

users.email_verified(mean)

But I'm having trouble figuring out how to get the same output as in the lesson, where they show all of the possible columns that can be aggregated:

email_verified     0.818947
referral_count     3.429474
balance           49.933263
dtype: float64

Can anyone assist? Thank you!

2 Answers

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Treehouse Project Reviewer

Hi there Nicole Buckenwolf ! :wave:

It's been a while since I've played with Pandas, but from looking around, I believe you may be able to get similar results using the agg() function. I don't have a project open to test it with unfortunately, but I'd give this a shot and see if it's close to what you're looking for.

aggregations = users.agg({'email_verified': 'mean', 'referral_count': 'mean', 'balance': 'mean'})
print(aggregations)

I hope this works out, I'll have to get back into the Pandas game a bit and test things out soon! :thumbsup:

Nicole Buckenwolf
Nicole Buckenwolf
8,721 Points

That worked! Seems obvious now that I look at it. Thank you!