-2
import pandas as pd

df = pd.DataFrame({'action': ['visited', 'clicked', 'switched'], 
                   'target': ['pricing page', 'homepage', 'succeesed']
                   'type': [np.nan, np.nan, np.nan],})`

I have an empty "type" column in the dataframe. I want a text to be written if the row certain condition satisfies it. e.g;

action=visited and target=pricing page get type=free

enter image description here

Naveed
  • 11,495
  • 2
  • 14
  • 21
  • [Please include your data in copyable form](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). If you've written code to solve your problem, please include it as well. – Nick ODell Nov 02 '22 at 21:38
  • added an answer, is that what you're looking for? – Naveed Nov 02 '22 at 22:19

1 Answers1

0
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
Naveed
  • 11,495
  • 2
  • 14
  • 21