I would like to create a new column 'column_new' based on values from column_1 and column_2 or column_3. If column_1 == 'C', then column_new is same value as column_2, but if column_1 == 'G', then column_new is same value as column_3.
I have tried:
def new_value(x):
if df1['column_1'] == 'C' :
return df1['column_2']
if df1['column_1'] == 'G':
return df1['column_3']
else:
return 'Other'
df1['column_new'] = df1['column_1'].apply(new_value)
error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Have also tried:
for row in df1:
if df1.loc[df1['column_1'] == 'C']:
df1['column_new'] = df1['column_2']
elif df1.loc[df1['column_1'] == 'G']:
df1['column_new'] = df1['column_3']
error: ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Some data:
column_1 column_2 column_3
C AAAACCCACCT ACCCA
C GTGGGCTAAAA GGCTA
G ATGGGCTTTTT GGCTT
G AGAAAGCCCGC AAGCC