I have a pandas dataframe with binary value columns. I would like to replace values in each cell with its frequency in rspective column in place. My question is how to keep track of the current column while using apply on the subset of columns like here: (to be applied from 8th columns to the end) :
train_data.ix[:,8:] = train_data.ix[:,8:].apply(x: what should come here?)
I know that train_data.ix[:,col_number].value_counts()[0]
will return number of zeros in col_number but how can I use it inside apply function?
df.ix[:,8:] = df.ix[:,8:].mean() * df.ix[:,8:]
if there are1
s and0
s only $\endgroup$value_counts()
is sorted, sovalue_counts()[0]
would return the most frequent element and not necessarily the number of0
s $\endgroup$