We truncated the value in str.extract for Series a and substituted the result in a new column b.
>>>df=pd.DataFrame([[abc def], ['123567'], ['qqqeeee']], columns=['a'])
>>df
a
0abc def
1 123 567
2qqqeeeee
>>>df['a'].str.extract(r'(.{3}$',expand=True)
0
0def
1 567
2eee
>>>df['b'] = df['a'].str.extract(r'(.{3})$',expand=False)
>>df
ab
0abc def def def
1 123 567 567
2qqqeeeeeeeee
© 2024 OneMinuteCode. All rights reserved.