In the data frame as below, I find special characters ''(,) inside it
when given df.head()
| SYSTEM_NAME | IP_ADDRESS |
|-------------|-----------------|
| AAAA | (xx.xx.xx.xx,) |
when viewed as dataframe inside IDE (pycharm)
| SYSTEM_NAME | IP_ADDRESS |
|-------------|--------------------|
| AAAA | ('xx.xx.xx.xx',) |
My trials
df['IP_ADDRESS'] = df['IP_ADDRESS'].str[:-2]
this makes the column value '0'
df['IP_ADDRESS'] = df['IP_ADDRESS'].str.replace(r"\(.*\)","")
this makes the column value 'nan'
I tried some other methods also to remove the special char
Required Output
| SYSTEM_NAME | IP_ADDRESS |
|-------------|--------------|
| AAAA | xx.xx.xx.xx |
CodePudding user response:
That looks like a tuple to me, so give .str[0]
a shot:
df['IP_ADDRESS'] = df['IP_ADDRESS'].str[0]