'How to slice every element of a column of a DataFrame? [duplicate]

I have a DataFrame and I am trying to remove first and last 3 letters of all the values in a column. Please refer the following:

column 1 column 2
val1 ABC12xyz
val2 ABC13xyz
val2 ABC14xyz

I want the output as following:

column 1 column 2
val1 12
val2 13
val2 14


Solution 1:[1]

Use the str accessor:

df['column 2'] = df['column 2'].str[3:-3]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mozway