Question: I want to get rid of characters in a string that comes after \ in python

```
df5['Abbreviation'] = df5['Abbreviation'].str.strip('\')
df5['Data Type'] = df5['Data Type'].str.strip('\')

```

error message:

```
File "<ipython-input-150-c7763a76caaf>", line 1

    df5['Abbreviation'] = df5['Abbreviation'].str.strip('\')
                                                            ^
SyntaxError: EOL while scanning string literal

```

Answer: 
You can't have only one `\` (or at the end, or a string with just an odd number of them) in a string literal without escaping it (because it will escape the closing quote), so you must escape it:

```
...str.strip('\\')

```

To remove everything after the backslash, you can use `apply` and `split`:

```
rem = lambda s : s.split('\\')[0] + '\\'

df5['Abbreviation'] = df5['Abbreviation'].apply(rem)
df5['Data Type'] = df5['Data Type'].apply(rem)

```

Also, as @G.Anderson noted, you can use just `...str.strip()` if your strings are like the ones on the title, in this case your code could be:

```
df5['Abbreviation'] = df5['Abbreviation'].apply(str.strip)
df5['Data Type'] = df5['Data Type'].apply(str.strip)

```
As mentioned in MrGeek's answer, you need to add two slashes to fix the initial syntax error. To remove everything after a backslash or special character such as a newline is found, no matter what it is, I found the simplest solution is this:

```
string = "Hello Stack \n\r\rOverflow!"
output = ""
print("In:", string)

for char in string:
    if char == "\\" or char == "\n" or char == "\r":
        break
    else:
        output += char

string = output
print("Out:", string)

```

Which Outputs:

```
In: Hello Stack 
Overflow!
Out: Hello Stack 
>>> 

```

This doesn't seem to be the *most* efficient way of doing it, but for small strings like your use case appears to be, the impact is unnoticable and does what is intended.