1

I looked in the Pandas library method (.replace), and I am trying to parse all the special characters in a pandas data frame. Meaning for a special character = '½', I am pulling the data as this:

import pandas as pd url = 'http://feeds.donbest.com/ScoresWebApplication/servicePage.jsp? type=SCHED&leagueId=0&schedDate=20081217&subscr=1' data = pd.read_html(url) 

I need to preserve the number and just replace this '½' with a 0.5 when trying this piece of code gets me this:

data[1].replace(regex=True,inplace=True,to_replace='½',value=0.5) 

It replaces the full data from 172½ for 0.5 instead of preserving its number like this 172.5.

1
  • the regex is returning True for a match and then replacing the entire thing. You'll need to run an apply, identify when it matches, when it does: find the integer part and add it to 0.5. Commented May 2, 2016 at 18:31

1 Answer 1

1

This should work (just change 0.5 to '.5'):

data[1].replace(regex=True,inplace=True,to_replace='½',value='.5') 

First of all, you want the replacement value to be a string, not an number. Secondly, you mean to replace '½' with '.5', not '0.5'.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey thank you so much I tried that at first, but didn't reference the table so it throw a error. Because I was trying to do it for the data frame, but I found a way to reference all the tables, so it finds all the tables and changes it in the fly. By doing a for loop. So I tried other stuff, read, looked videos and I was not getting the answer. Have a great day wherever you are.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.