Open asadmehdi785 opened 6 years ago
MUCH better! This is a great tip as I still feel somewhat nervous about imputing the lambda function incorrectly. The above code is pretty much saying the expression in my head and typing it out.
Hi Asad,
When I typed in the simplified code, I get an attribute error further down the script:
`--------------------------------------------------------------------------- AttributeError Traceback (most recent call last)
Can you try to restart the kernel by going to Kernel -> Restart & Run All? Sometimes that helps when it doesn't recognize certain variables.
Hmm, it gives the same message.
Okay. In the step before, can you print out category_pivot
and show what it looks like for you?
Unfortunately, it won't give me the screen from my original submission:
Ah sorry, I should have been more clear. Can you add a statement to output category_pivot
after this code:
category_pivot = category_pivot.rename(columns={'False': 'not_protected', 'True': 'protected'})
So you can change that part to run it like this:
category_pivot = category_pivot.rename(columns={'False': 'not_protected', 'True': 'protected'})
print category_pivot
Can you show what is printed when you run that?
It looks like the the above script isn't renaming the columns to their new names, which the following code isn't able to find a category named 'protected'.
category_pivot = category_pivot.rename(columns={'False': 'not_protected', 'True': 'protected'}) print category_pivot
is_protected category False True 0 Amphibian 72 7 1 Bird 413 75 2 Fish 115 11 3 Mammal 146 30 4 Nonvascular Plant 328 5 5 Reptile 73 5 6 Vascular Plant 4216 46
I changed one thing to make the fixed lambda code work:
Previously, I did not use the columns
property to rename the categories True
and False
. After changing the script to:
category_pivot.columns = {'category', 'not-protected', 'protected']
our following script finally works.
Ah okay! I was wondering about that piece of code, honestly I didn't think it made a difference but I guess it's better to use the columns
property here. Nice job with that!
https://github.com/tekasian/intro-data-capstone-biodiversity/blob/297a56430354b6ef4894b9f0bcaa2b78767381c9/Biodiversity_Capstone_Project_Bryan_Leung/biodiversity.py#L157
This will work fine, but we can achieve the same result by using a simpler line of code:
This means that when
species.conservation_status != 'No Intervention'
, it will returnTrue
, andFalse
otherwise.