Different column in Pandas

Hi guys,
I just got a few questions on pandas: 1) when do we use the bracket for column and when can we use pd.’ column name’ 2) is my code wrong? cuz the only thing I did differently was I did else the other way(<40 then else) 3) what’s the use of \ in between the lambda function?

1 Regarding the subscript syntax [key] vs. the dot syntax this question might help- https://discuss.codecademy.com/t/dataframes-variables-attributes/604101

2 Wrong is difficult to say, you’ve not really made it clear what you’re doing. It might be worth linking the lesson and explaining your task along with what you expected to happen vs. what you got.

3 The \ is for explicit line joining (e.g. for where newlines be treated as different statements if they were split by a newline)- https://docs.python.org/3/reference/lexical_analysis.html#explicit-line-joining. You’ll almost never see them since there are normally much better ways to organise code.

Since your lambda is complex, multi-line and named consider just using a regular function, they tend to be much easier to read.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.