import pandas as pd
df = pd.DataFrame({'action': ['visited', 'clicked', 'switched'],
'target': ['pricing page', 'homepage', 'succeesed']
'type': [np.nan, np.nan, np.nan],})`
我在dataframe中有一个空的"type“列。如果某一行条件满足的话,我想要写一个文本。例如;
action=visited
和target=pricing page
get type=free
发布于 2022-11-02 14:18:41
df.loc[df['action'].eq('visited') & df['target'].eq('pricing page'), 'type'] = 'free'
action target type
0 visited pricing page free
1 clicked homepage NaN
2 switched succeesed NaN
https://stackoverflow.com/questions/74295854
复制