0

There are few rows in the DataFrame and these are the columns 'Product', 'Category', 'Rating', 'Reviews' and 'Price'.

The DataFrame looks like this:

  Product    Category      Rating      Reviews       Price
1  'A'       small           4           10           100
2  'B'       Medium          3           15           200
3  'C'       Medium          3           15           125
4  'A'       small           4           25           100
5  'A'       Medium*         2           10           250
6  'D'       Large           4           10           100
7  'B'       Medium          3           15           200
8  'B'       Large*          3           15           200

I want to replace specific values in the "Category" column (Indicated by *) on the DataFrame.

The resulting DataFrame should look like this:

  Product    Category      Rating      Reviews       Price
1  'A'       small           4           10           100
2  'B'       Medium          3           15           200
3  'C'       Medium          3           15           125
4  'A'       small           4           25           100
5  'A'       small*          2           10           250
6  'D'       Large           4           10           100
7  'B'       Medium          3           15           200
8  'B'       Medium*         3           15           200
WF30
  • 213
  • 1
  • 3
  • 16
  • 4
    What is the logic you're following to dictate a row needs to change? – PacketLoss Jan 18 '21 at 04:15
  • Use iloc or loc to change. Specify the column and row details and do assignment with the value you want to change. Stackoverflow has so many examples of these – Joe Ferndz Jan 18 '21 at 06:11
  • Does this answer your question? [How to select rows from a DataFrame based on column values](https://stackoverflow.com/questions/17071871/how-to-select-rows-from-a-dataframe-based-on-column-values) – Joe Ferndz Jan 18 '21 at 06:12

1 Answers1

1

You could use:

df_name.at[5, 'Category'] = 'small'

ishmamt
  • 177
  • 9