说,我有一个数据框df,其中的一列是:
df['letters'] = pd.Series(['a','a','m','a'])
,我想向df添加一个消息列,如下所示: (如果存在诸如index()之类的东西,那会很好。)
message_col = np.where(df['letters']=='a','found','missing at index'+str(df['letters'].index()))
结果将是:
df['message_col'] = pd.Series(['found','found','missing at index 2','found'])