I have a dataframe:
maturity spot rate
0 SONIA GBP 1W 0.020
1 SONIA GBP 2W 0.030
2 SONIA GBP 1M 0.030
3 SONIA GBP 2M 0.031
4 SONIA GBP 3M 0.031
5 SONIA GBP 4M 0.031
6 SONIA GBP 5M 0.031
7 SONIA GBP 6M 0.032
8 SONIA GBP 7M 0.032
9 SONIA GBP 8M 0.033
10 SONIA GBP 9M 0.034
11 SONIA GBP 10M 0.035
12 SONIA GBP 11M 0.036
13 SONIA GBP 1Y 0.038
14 SONIA GBP 18M 0.063
15 SONIA GBP 2Y 0.099
16 SONIA GBP 3Y 0.206
17 SONIA GBP 4Y 0.302
18 SONIA GBP 5Y 0.395
19 SONIA GBP 6Y 0.474
20 SONIA GBP 7Y 0.547
21 SONIA GBP 8Y 0.611
22 SONIA GBP 9Y 0.669
23 SONIA GBP 10Y 0.722
24 SONIA GBP 12Y 0.800
25 SONIA GBP 15Y 0.869
26 SONIA GBP 20Y 0.905
27 SONIA GBP 25Y 0.903
28 SONIA GBP 30Y 0.842
29 SONIA GBP 40Y 0.788
30 SONIA GBP 50Y 0.738
I have a line of code which basically from the maturity column gets the last 3 characters e.g: for the first row, it obtains 1W instead of the entire string:
data['maturity'] = data['maturity'].str[-3:]
I wanted to ask if there is a a way I can write the code so that it is more flexible, ie if I have another row where say I have SONIA GBP 150W (unlikely but gets the point across), I can still obtain the 150W.