Search code examples
pythonpandasdataframeboolean-operations

How should I change the value to 0 without remove the rows


I have a dataframe which contains three rows, and I want to make the amount to 0 for those LeadID? =0 (not a leaddeal). Don't remove them. Can anyone help me with this? Thanks for the help.

raw data

LeadID  LeadID? Amount
31578    1       $189
17698    1       $187
21891    1       $191
25062    1       $127
25062    0       $127
15133    1       $167
15133    0       $167
14321    1       $122
19148    1       $181

rows

DataFrame


Solution

  • You can assign values to slices of your dataframe by indexing using loc:

    df.loc[df['LeadID?'] == 0, 'Amount'] = '$0'