I am struggling with something that seemed trivial, but apparently it is not. General image: data- pandas dataframe - contains (among others) TOTAL_VISITSand columns NUM_PRINTS.
Purpose: given parameter NUM_PRINTS, find the lines where NUM_prints = num_printsand fill with the nangiven number.
Where I left off, and that didn't make sense:
indices= data['NUM_PRINTS'] == num_prints
data.loc[indices,'TOTAL_VISITS'].fillna(5,inplace=True)
This should work the way I know and read. didn’t fill the nana with anything in practice, it seemed that it worked with a copy or something, since nothing had changed in the original object.
What works:
data.loc[indices,'TOTAL_VISITS'] = 2
this fills column 2 with a condition num_print, but does not consider nans.
data['TOTAL_VISITS'].fillna(0, inplace=True)
this fills nans in general visits from 0, but does not account for the condition NUM_PRINTS.
, for .iloc, , .