There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hi there,
I was wondering if there is a smarter (quicker) way to erase the column ‘gender_age’ in this exercise, instead of rewriting all the column headers again.
E.g. is there a .drop_columns() ? I tried it but it didn’t work out.
Any time I try to do question 3 I get an “Index object is not callable” even after just copying the answer straight from the solution. Anyone have any idea why this happens? This happens with soooo many lessons
I have just typed “print(students.columns())” for task 1 within this lesson, and had an error message that reads “‘Index’ object is not callable”. Despite the error message the lesson has marked the first task as complete, and allowed me to progress to the next task in the lesson. I have had this error on several lessons, but don’t understand what it means. Please can someone help by explaining the error? thanks.
not sure, but the hint seems to have an error. I don’t believe (correct me if I’m wrong please ) that a column can be created using ‘students.gender=…’ I think one must use brackets, ‘students[‘gender’]=…’
When trying it without .str like:
students[‘gender’] = students[‘gender_age’][0:1]
Returns M14 for the first row and then NaNs. It is as if Python interprets the [0:1] as an index for the column . What is it about str that make Python look at the contents of the row instead?
Using students["gender_age"][0:1] returns a pandas Series object that has been effectively sliced by row (not a single string object and not a Series where every string has been sliced). This behaviour is similar to Python’s normal positional indexing/slicing, e.g. with a list the subscript [3] would give you the fourth element but the subscript [3:4] (slicing) would give you a list object containing the third element.
So your new column "gender" is basically being populated by a Series with a single element so every other element is just filled in as effectively missing. Hopefully that explains the NaNs.
A bit like a vectorised getter as you can work with the actual contents of a Series without using standard looping methods. So it’s not Python itself but an option Pandas added in a few special cases, the link would provide much more detail.