I have data as below:
I want to mask this data as below one
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("(?<! )","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("(?<! ).","X",readFiles)
It gives below error:
>>> finalValues = re.sub("(?<! ).","X",readFiles) Traceback (most recent call last): File "<stdin>", line 1, in <module> 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.