import numpy as np
import pandas as pd
I have a df looks like this
X
0 100A
1 100B
2 100B
3 500A
4 500B
5 400B
6 700A
7 200B
8 400B
9 900A
10 800B
My goal is to change them (string) to integer and divide the number by 10 inside the string if it contains 'A'
X
0 10
1 100
2 100
3 50
4 500
5 400
6 70
7 200
8 400
9 90
10 800
I have tried to use for loop for the whole column
for i in df.X:
if 'A' in i:
y = i.replace('A','')
y = int(y)/10
print(y)
else:
k = i.replace('B','')
k = int(k)
print(k)
But I can only print them out and I dont know how to replace the value directly and store them in the column. Also, this method seems to be slow? Is there a better methods in pandas? Thanks!