I'm struggling to simplify my irregular nested np.where clauses. Is there a way to make the code more readable?
df["COL"] = np.where(
(df["A1"] == df["B1"]) & (df["A1"].notna()),
np.where(
(df["A1"] == df["C"]),
np.where(
(df["A"] == df["B"]) & df["A"].notna() & (df["A"] != df["A1"]),
"Text1",
df["A1"]
),
"Text2"
),
np.where(
(df["A"] == df["B"]) & (df["A"].notna()),
np.where(
(df["A"] == df["C"]),
df["A"],
"Text1"
),
np.where(
(df["C"].notna()),
df["C"],
"Text3"
)
)
)