Search code examples
pythonpandasdata-analysis

How to remove a Alphabetical char between two numbers in a cell in pandas?


enter image description here

Goal: I have a column called Resolution. What you can see in the picture. Let's say the first cell 1600 x 900 I need to get rid of the x in order to have an integer value. So the results should be 1600 900. How can I do that?

I have tried to search online I could not find an answer.


Solution

  • Try using replace:

    df['Best_Resolution'] = df['Best_Resolution'].str.replace('x', ' ')
    

    Or if you want the value as integer:

    df['Best_Resolution'] = (
        df['Best_Resolution'].str.replace('x', '')
        .astype(int)
    )
    

    It might fail if there are values that cannot be converted to integer.