I mostly understanding how the axes work when indexing (i.e., rows = 0, columns = 1). I generally try to say the logic in my head (unsure if this is a good way to learning programming). But from a previous lesson:
def percentages(col): div = col/happiness2015["Happiness Score"] return div*100 factor_percentages = happiness2015.loc[:,factors].apply(percentages)
I understand this as “down these rows, for the columns in factors, apply percentages function at one column at a time”.
However for the lesson in this tag:
def cheap_reas(row): if row["Price"] < 5: return "cheap" else: return "reasonable" affordable_apps["affordability"] = affordable_apps.apply(cheap_reas, axis = 1)
I don’t fully understand the logic of using axis 1/ can’t explain it well.
Is it because of the nature of df.apply is to apply a function on a column axis (axis =1) one at a time and the function is referencing a specific column, “Price” makes it so we have to pick axis = 1?