Videos
I've been doing a Kaggle course about pandas and found a line I don't really understand, so I was hoping someone could help me out a bit.
The line would be this:
n_trop = reviews.description.map(lambda desc: "tropical" in desc).sum()
It wants to count the number of times 'tropical' appears in the description column of a table.
What does 'desc' stand for? Is it description? In that case, can I shorten column names in pandas whenever I feel like it?
I believe I may have a problem with lambdas but I'm quite lost here.
I am having a problem with map function in pandas. I am trying to map new value to some rows but it's returning all the rows to NaN. I have tried this function on another column and seems to work fine but not working on this one.
This is the code that works fine:
df['Hobbyist'] = df['Hobbyist'].map({'Yes':True, 'No': False})
and this one is returning all rows to NaN :
df['EdLevel'] = df['EdLevel'].map({"Master’s degree(M.A., M.S., M.Eng., MBA, etc)" : "Master's Degree", "Bachelor’s degree(B.A., B.S., B.Eng., etc.)": "Bachelor’s degree"})
I know that it's very basic but i can't seem to understand why one is working and other is not. Can someone please help me.