.loc in pandas 在一列中查找名称并查看它是否存在于另一列中
.loc in pandas looking up a name in one column and seeing if it exists in another column
在 Pandas 中,我试图在 A 列中查找名称的字符串值,如果它与 B 列中的值相同,我想在 C 列中输入 1,在 C 列中输入 0如果没有。
所以,如果我在 A 列和 B 列中查找 "Kyrie Irving",如果他不存在,我想在 C 列中输入 1,在 C 列中输入 0。
也许你正在寻找np.where ie11=]
df['colC'] = np.where(df['colA'] == df['colB'],1,0)
IIUC,使用isin
:
df['ColC'] = df.ColA.isin(df.ColB).astype(int)
在 Pandas 中,我试图在 A 列中查找名称的字符串值,如果它与 B 列中的值相同,我想在 C 列中输入 1,在 C 列中输入 0如果没有。
所以,如果我在 A 列和 B 列中查找 "Kyrie Irving",如果他不存在,我想在 C 列中输入 1,在 C 列中输入 0。
也许你正在寻找np.where ie11=]
df['colC'] = np.where(df['colA'] == df['colB'],1,0)
IIUC,使用isin
:
df['ColC'] = df.ColA.isin(df.ColB).astype(int)