I have a dataframe with prices in $. I want to do calculations on it but the $ makes it impossible. I’m trying to remove it using df.iloc[:, 4].replace("$", " ", regex=True)
but unfortunately nothing changes. If I add inplace=True
then whe whole word disappears. What am I doing wrong? Tried many stackoverflow posts but nothing works. I cant use str.replace()
because its about the whole column not one word.
My code:
order_id quantity item_name choice_description item_price 0 1 1 Chips and Fresh Tomato Salsa NaN $2.39 1 1 1 Izze [Clementine] $3.39 2 1 1 Nantucket Nectar [Apple] $3.39 3 1 1 Chips and Tomatillo-Green Chili Salsa NaN $2.39 4 2 2 Chicken Bowl [Tomatillo-Red Chili Salsa (Hot), [Black Beans... $16.98 ... ... ... ... ... ... 4617 1833 1 Steak Burrito [Fresh Tomato Salsa, [Rice, Black Beans, Sour ... $11.75 4618 1833 1 Steak Burrito [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese... $11.75 4619 1834 1 Chicken Salad Bowl [Fresh Tomato Salsa, [Fajita Vegetables, Pinto... $11.25 4620 1834 1 Chicken Salad Bowl [Fresh Tomato Salsa, [Fajita Vegetables, Lettu... $8.75 4621 1834 1 Chicken Salad Bowl [Fresh Tomato Salsa, [Fajita Vegetables, Pinto... $8.75
Then I call function replace() but the table stays the same:
df.iloc[:, 4].replace("$", " ", regex=True)
Thanks in advance
Advertisement
Answer
df.iloc[:, 4].replace("$", " ", regex=True)
Alternatively:
df.iloc[:, 4].replace("$", " ")