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 with MrGeek's answer, you must escape the backslash. 

If you want to remove anything after the backslash, simply do the following:

```
test_str = test_str.str.split('\\')[0] 

```

The .split returns an array, and since we only want the contents leading to the first backslash, we can just get the first index using [0].

This will get everything up until the first backslash. If you want to include the backslash, then just append it at the end:

```
test_str = test_str.str.split('\\')[0] + "\\"

```