So this should be the easiest thing on earth. Pseudocode:
Replace column C with NaN if column E is NaN
I know I can do this by pulling out all dataframe rows where column E is NaN, replacing all of Column C, and then merging that on the original dataset, but that seems like a lot of work for a simple operation. Why doesn't this work:
Sample data:
dfz = pd.DataFrame({'A' : [1,0,0,1,0,0],
'B' : [1,0,0,1,0,1],
'C' : [1,0,0,1,3,1],
'D' : [1,0,0,1,0,0],
'E' : [22.0,15.0,None,10.,None,557.0]})
Replace Function:
def NaNfunc(dfz):
if dfz['E'] == None:
return None
else:
return dfz['C']
dfz['C'] = dfz.apply(NaNfunc, axis=1)
And how to do this in one line?