Home > Software design >  Data analysis question PYTHON about subsetting and selecting
Data analysis question PYTHON about subsetting and selecting

Time:11-11

I have a question , i am actually learning data analysis with python , and i can't see the difference when we use these lines of code :

rice_consumption = food_consumption[food_consumption["food_category"]=="rice"]

for example we want to define rice_consumption, why here do we rewrite the dataframe "food_consumption" twice in the line, and when and why do we write it only once in another line of code, like that :

rice_consumption = food_consumption["food_category"]=="rice"

Thanks for helping !

CodePudding user response:

food_consumption["food_category"]=="rice"

Above line gives you a mask, which are composed of True or False. food_consumption with the mask as the argument can return you the items where mask value is True.

  • Related