user_v27
user_v27

Reputation: 423

Removing special character from dataframe

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 |

Upvotes: 0

Views: 76

Answers (1)

user17242583
user17242583

Reputation:

That looks like a tuple to me, so give .str[0] a shot:

df['IP_ADDRESS'] = df['IP_ADDRESS'].str[0]

Upvotes: 2

Related Questions