Question: **Target** : if the **8th (or n of )** of character in string **match condition**, **then update in new column**

**By word in a single string :**

```
# if i want to check the 3rd character
IN[0]:  s = "apple"
        s[2]
OUT[0]: 'p'

```

**Code** : 

```
tt = pd.DataFrame({"CC":["T020203J71500","Y020203K71500","T020407JLX100","P020403JLX100"])

tt["NAME"] = pd.np.where(tt["CC"][7].str.contains("J"),"JANICE",
               pd.np.where(tt["CC"][7].str.contains("K"),"KELVIN",
               pd.np.where(tt["CC"][7].str.contains("X"),"SPECIAL","NONE")))

```

**Problem** :
Apparently `[7]` is not a python practice

**In R data.table :**

```
tt[grepl("J",str_sub(CC,8,8)),
      "NAME":="JANICE"]
tt[grepl("K",str_sub(CC,8,8)),
      "NAME":="KELVIN"] # .... can achieve by doing like this 

```

How can i do this in Python ?

Answer: 
Use Regex.

**Ex:**

```
import re

s = "2019-07-25 15:23:13 [Thread-0] DEBUG  - Serial : INFO: QQQ=00000D00001111 AAA=8 BBB=0 CCC=0 DDD=1.08% XXX=2401"
m = re.search(r"DDD=(.*?)%", s)  #if you want it to be strict and get only ints use r"DDD=(\d+\.?\d*)%"
if m:
    print(m.group(1))

```

**Output:**

```
1.08

```
Use string find operation:

**Example**

```
my_string="2019-07-25 15:23:13 [Thread-0] DEBUG  - Serial : INFO: QQQ=00000D00001111 AAA=8 BBB=0 CCC=0 DDD=1.08% XXX=2401"
fst = my_string.find("DDD=")
snd = my_string.find("%")
if fst >= 0 and snd >= 0
    print(my_string[fst+4,snd])

```

**Output**

```
1.08

```

Or you can use split:

**Example**

```
my_string="2019-07-25 15:23:13 [Thread-0] DEBUG  - Serial : INFO: QQQ=00000D00001111 AAA=8 BBB=0 CCC=0 DDD=1.08% XXX=2401"
(fst,snd) = my_string.split("DDD=");
(trd,fourth) = snd.split("%");
print(trd)

```

**Output**

```
1.08

```