I have a dataframe which looks like this
df = pd.DataFrame({
'price': {0: 639.0, 1: 639.0, 2: 849.0, 3: 849.0, 4: 128.0},
'special_price': {0: '599',
1: '599',
2: '849',
3: '849',
4: 'data not available'}})
i would like to search the dataframe and replace any value of 'data not available' in column['special_price']
with the corresponding from the column['price']
the result should look like
df = pd.DataFrame({
'price': {0: 639.0, 1: 639.0, 2: 849.0, 3: 849.0, 4: 128.0},
'special_price': {0: '599',
1: '599',
2: '849',
3: '849',
4: '128'}})
What is the fastest way to do that
I have tried
def replaceDaWithNil(row):
if row['special_price'] == 'data not available':
row['special_price'] = row['price']
return row
df[['price','special_price']].apply(replaceDaWithNil, axis = 1)
This takes a very long time, so im wondering if there is a faster way