Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
数据框结构:
df = pd.DataFrame([[1,2,3], ['Active','Deleted','Active'], [np.nan,2,np.nan]], columns=list('ABC'))
如果 B 列的值是“已删除”,那么我想将 A 列的值复制到 C 列,否则将其保留为 Nan。我怎样才能在熊猫中做到这一点?
你想要where:
where
df['c'] = df['a'].where(df['b']=='A')