WF30
WF30

Reputation: 253

How to replace a string value on a specific column by keeping other values unchanged in python DataFrame

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

Upvotes: 0

Views: 129

Answers (1)

ishmamt
ishmamt

Reputation: 186

You could use:

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

Upvotes: 1

Related Questions