I'm trying to use pandas to look at two existing columns in a tsv file and add a new column where df['padj'] < 0.01
and df['log2FoldChange'] > 0.1
. I would like the new column to contain the string Up-Regulated
where this condition is met.
This is the code I've come up with so far:
if df[(df['padj'] < 0.01) & (df['log2FoldChange'] > 0.1)]:
df["Up/Down-Regulated"] = "Up-Regulated"
However, I'm running into this error:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
CodePudding user response:
Using pandas.DataFrame.loc
df.loc[(df['padj'] < 0.01) & (df['log2FoldChange'] > 0.1), ["Up/Down-Regulated"]] = "Up-Regulated"