I have a dataframe below
df=pd.DataFrame(np.random.randn(6,3),index=list("ABCDEF"),columns=list("XYZ"))
df.reset_index(inplace=True)
df
I want to have a new column named "Q". The values under column "Q" shall be calculated based on the labels under index column with the following three conditions:
conditions=[(df["index"]== "A"|"B"|"C"|"D"),(df["index"]== "E"),(df["index"]== "F")]
returned_value=[df["X"]+df["Y"],df["Y"]*2,df["Z"]]
So I was thinking using
df["Q"]=np.select(conditions, returned_value)
I however got the error after defining the conditions. I first used or, and got another error, and then changed to |, but got the following. Any hints on how can I achieve what I want?
TypeError: unsupported operand type(s) for |: 'str' and 'str'