Replace method in pandas not giving expected result I have data as below:

123.12.23.2
110.22.21.23


I want to mask this data as below one

1xx.xx.xx.x  


So I tried below code :

 readFile = pd.read_csv("C:/Users/siddhesh.kalgaonkar/Desktop/data01.txt",header=None)
 readFile.columns = ['IP']
 readFile['IP']=readFile['IP'].str.replace("(?&lt;! )","X").astype('str')
 readFile


but I gives me data as below one which is not correct:

                                                  IP
0  XXXXXXXXXXXXXXXXXXX 1XXXXXXXXXXXXXXXXXXXXXXXXX...
1  XXXXXXXXXXXXXXXXXXX 1XXXXXXXXXXXXXXXXXXXXXXXXX...
2  XXXXXXXXXXXXXXXXXXX 1XXXXXXXXXXXXXXXXXXXXXXXXX...


I am new to pandas. So where am I going wrong ?

Also, I want to do it without pandas because the platform on which I would be deploying this code may be won't have pandas. So need to be ready for the other scenario as well. Below is my code:

readFiles=open("C:/Users/siddhesh.kalgaonkar/Desktop/data01.txt","r")
 finalValues = re.sub("(?&lt;! ).","X",readFiles)  


It gives below error:

&gt;&gt;&gt; finalValues = re.sub("(?&lt;! ).","X",readFiles)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "C:\Users\siddhesh.kalgaonkar\AppData\Local\Programs\Python\Python36\lib\re.py", line 191, in sub
    return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object


I want to split this data on the basis of delimiter (in case I have multiple columns) and then I have to apply regex logic. Please help me out here.
This is pure(almost) python:

list(map(lambda x: x[0] + '.'.join(['X' * len(c) for c in x[1:].split('.')]), my_df['IP']))


Explanation:
 - Use the map to iterate over each row in my_df['IP'] column.
 - Per each IP value, split into first char and others using the x[0], x[1:]
 notation.
 - Get each part in x[1:] using the split method.
 - For each part get its length and accordingly create a string made of X's.
 - Rejoin this X's string into one string with '.' between them.  

If using python2 you dont need the list.