I have a Panda DataFrame that looks somewhat like this:
df = pd.DataFrame({'ID' : ['O60829','O60341','Q9H1R3'], 'TOTAL_COVERAGE' : ['yes','yes','no'], 'BEG_D' : ['1','1','500'], 'END_D' : ['102','25','600'], 'BEG_S' : ['1','1','1'], 'END_S': ['102','25','458']})
And I want to iter over every row, check the value of 'TOTAL_COVERAGE' and if it's 'yes', perform a mathematical operation over the other values, ie:
for index, row in df.iterrows():
df['%'] = df.apply(lambda x : ((int(x['END_S'])*100)/int(x['END_D'])) if x['TOTAL_COVERAGE'] == 'yes' else '')
But I'm getting the error: KeyError: 'TOTAL_COVERAGE'
There must be an easy fix that I'm not seeing. Thanks in advance!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…