对于一个数据框架。
df = pd.DataFrame({"A":[0,0],"B":[0,1],"C":[1,2],"D":[2,2]})
当数值为2或某一数值时,如何获得列名或列索引
并把它放在df的一个新列里,比如df["TAG"]
df = pd.DataFrame({"A":[0,0],"B":[0,1],"C":[1,2],"D":[2,2],"TAG":[D,C]})
i tried
df["TAG"]=np.where(df[cols]>=2,df.columns,'')
where [cols] is the list of df columns
到目前为止,我只能找到在Pandas中匹配一个值时如何找到行的索引。
In excel we can do some approach using MATCH(TRUE,INDEX($A:$D>=2,0),) and apply to multiple rows
希望得到任何帮助或提示
非常感谢你的到来