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

Verified Email List - Pandas Challenge

Hello guys, i'm stuck at this pandas challenge. I've tried based on the tutorials too, but nothing changed in the end and it keeps printing the original file. Here's my work so far:

TODO: Narrow list to those that have email verified.

The only columns should be first, last and email

email_list = users[:] email_list.loc[email_list['email_verified'] == True, ['first_name','last_name','email']].max() email_list.sort_values(axis='last_name', ascending=True, inplace=False, na_position='first')

TODO: Remove any rows missing last names

no_last = email_list.loc[email_list['last_name'] == ' '] if len(no_last) > 0: email_list.drop(index=[no_last], inplace=True)

TODO: Ensure that the first names are the proper case

email_list.loc[email_list.first_name.str.islower()]

Return the new sorted DataFrame..last name then first name ascending

email_list

2 Answers

Hi Ektoras,

I'm learning this alongside you. I'm not 100% sure if your line here does what you want:

email_list.loc[email_list['email_verified'] == True, ['first_name','last_name','email']].max() 

This is how I've done it; hopefully my code might be helpful?

TODO: Narrow list to those that have email verified.

The only columns should be first, last and email

emails_verified = users[users['email_verified']]
emails_verified.shape  # OPTIONAL CHECK

email_list = emails_verified[['first_name', 'last_name', 'email']]

email_list.shape  # OPTIONAL CHECK

Remove any rows missing last names

This part I'd like more clarity on -- my code is imperfect, because if NAs happen to appear in other columns, those records would get removed too -- not what the instructions ask:

email_list.dropna(inplace=True)

TODO: Ensure that the first names are the proper case

firstname_lowercase_records = users.first_name.str.islower()

users.loc[firstname_lowercase_records, 'first_name'] = users.first_name.str.title()

users.loc[firstname_lowercase_records]  # OPTIONAL CHECK

Just to ask anyone out there: is there a better way to explicitly remove records of missing last names, without removing all records with missing data? If so, please help. Thank you!

TODO: Remove any rows missing last names

If there's a cleaner way to write out these scripts please let me know I'd like to learn about it!

CHALLENGE - Verified email list

TODO: Narrow list to those that have email verified.

The only columns should be first, last and email

email_list = users[users.email_verified == True]
email_list = email_list.loc[:, ["first_name", "last_name", "email"]]

TODO: Remove any rows missing last names

email_list.dropna(inplace = True)

TODO: Ensure that the first names are the proper case

first_name_lowercase_list = email_list.first_name.str.islower()
email_list.loc[first_name_lowercase_list, 'first_name'] = email_list.first_name.str.title() 

Return the new sorted DataFrame..last name then first name ascending

email_list.sort_values(['last_name', 'first_name'], ascending=[True, True])