I have a dataframe and would like to replace some of the entries based on a regular expression match. Here is a toy example:
import pandas as pd
dfl = pd.DataFrame(np.random.randn(5,4), columns=list('ABCD'))
A B C D
0 0.995647 -0.507860 0.246656 0.400589
1 -0.149536 -0.485617 -0.132031 0.214816
2 -0.730974 -0.932630 0.625197 1.887758
3 2.812800 0.329197 0.233513 0.140899
4 -1.897268 0.072307 0.790148 0.096455
Now let's convert all the entries to be strings.
dfl = dfl.astype(str)
Now I would like to replace every number that contains 40, say, with the word boat say.
I tried:
dfl = dfl.replace(r'.*40.*', "boat")
but this doesn't modify dfl at all.
What am I doing wrong?