I have a dataframe and I would like to replace all the cells that contain the string "low" with just "low". Could anyone help me please? Below is my dataframe.
I have tried to this with replace and loc:
df.loc[df['Stock'].str.contains('low').replace(to_replace=None,value="low",regex=True)]
however this gives me a regex error. I have tried reading the documentation for replace too, but havent gotten much further as it wouldnt be an exact match that I would be replacing.
I have tried it by getting a list about what contains "low" but that hasnt been working either:
list(df['Stock'])
['low stock', 'low stck', 'low stock', 'in stock', 'in stock', 'instock', 'lowstock', 'low', 'low on stock', 'in stock', 'in stock a lot', 'low_ on stock', 'low', 'low_on_stock ', ' lowstock', 'in stock', 'instock']
list(df.loc[df['Stock'].str.contains('low')])
['Company', 'Country', 'Stock']
list(df['Stock'].str.contains('low'))
[True, True, True, False, False, False, True, True, True, False, False, True, True, True, True, False, False]
Company Country Stock
0 Michelin USA low stock
1 Continental USA low stck
2 Continental USA low stock
3 Michelin USA in stock
4 Michelin USA in stock
5 Michelin USA instock
6 Michelin USA lowstock
7 Michelin USA low
8 Michelin USA low on stock
9 Pirelli USA in stock
10 Goodyear USA in stock a lot
11 Michelin USA low_ on stock
12 Continental USA low
13 Michelin USA low_on_stock
14 Continental USA lowstock
15 Michelin USA in stock
16 Michelin USA instock