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:
JavaScript
x
13
13
1
order_id quantity item_name choice_description item_price
2
0 1 1 Chips and Fresh Tomato Salsa NaN $2.39
3
1 1 1 Izze [Clementine] $3.39
4
2 1 1 Nantucket Nectar [Apple] $3.39
5
3 1 1 Chips and Tomatillo-Green Chili Salsa NaN $2.39
6
4 2 2 Chicken Bowl [Tomatillo-Red Chili Salsa (Hot), [Black Beans $16.98
7
8
4617 1833 1 Steak Burrito [Fresh Tomato Salsa, [Rice, Black Beans, Sour $11.75
9
4618 1833 1 Steak Burrito [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese $11.75
10
4619 1834 1 Chicken Salad Bowl [Fresh Tomato Salsa, [Fajita Vegetables, Pinto $11.25
11
4620 1834 1 Chicken Salad Bowl [Fresh Tomato Salsa, [Fajita Vegetables, Lettu $8.75
12
4621 1834 1 Chicken Salad Bowl [Fresh Tomato Salsa, [Fajita Vegetables, Pinto $8.75
13
Then I call function replace() but the table stays the same:
df.iloc[:, 4].replace("$", " ", regex=True)
Thanks in advance
Advertisement
Answer
JavaScript
1
2
1
df.iloc[:, 4].replace("$", " ", regex=True)
2
Alternatively:
JavaScript
1
2
1
df.iloc[:, 4].replace("$", " ")
2