I have a large DataFrame
that I need to clean, as a sample please look at this dataframe:
import pandas as pd
cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4','Suzuki'],
'Price': ['22000.T','25000.T','27000','.TPX','.NKM1']
}
df = pd.DataFrame(cars, columns = ['Brand', 'Price'])
print (df)
I want to remove '.T'
from the end of the words, and only '.'
from the beginning of the rows that contain the.
by the following line of code, I could remove the '.T'
df['Price'].replace('.T', '', regex=True)
but it also removed the 'T'
from the '.TPX'
any advice on this is appreciated.
0 22000
1 25000
2 27000
3 PX
4 .NKM1
Name: Price, dtype: object
Also for removing the '.'
when I add this line
f['Price'].replace('.', '', regex=True)
I get a different dataframe as what I expected
0
1
2
3
4
Name: Price, dtype: object