I have a column in a dataframe and need for every entry just the index 2-4 of the string.
For example
A
AB101CD
AB101CD
AB101CD
result:
A
101
101
101
>Solution :
You could use df.column.apply
import pandas as pd
a = ['AB101CD','AB101CD','AB101CD']
df = pd.DataFrame(a)
df.columns = ['A']
df.A.apply(lambda x:x[2:5])
This gives:
0 101
1 101
2 101
Name: A, dtype: object
You could set it as column:
df.A = df.A.apply(lambda x:x[2:5])