Having the following DF :
Index Date
1D 9/13/2022
1W 9/19/2022
2W 9/26/2022
3W 10/3/2022
1M 10/12/2022
2M 11/14/2022
3M 12/12/2022
4M 1/12/2023
5M 2/13/2023
6M 3/13/2023
7M 4/12/2023
8M 5/12/2023
9M 6/12/2023
10M 7/12/2023
11M 8/14/2023
12M 9/12/2023
18M 3/12/2024
2Y 9/12/2024
3Y 9/12/2025
4Y 9/14/2026
5Y 9/13/2027
6Y 9/12/2028
7Y 9/12/2029
8Y 9/12/2030
9Y 9/12/2031
10Y 9/13/2032
12Y 9/12/2034
15Y 9/14/2037
20Y 9/12/2042
The idea would be to do a loop, and to do :
if DF.index[i][-1] == 'Y':
if int(self.dfcurve.index[i+1][:-1])-int(self.dfcurve.index[i][:-1])!= 1:
###Add Missing Index:
index_val = int(self.dfcurve.index[i][:-1]) +1
index_val = str(index_val)+'Y'
### Example of missing index :
## 11Y
## 13Y
## 14Y
## 16Y
## 17Y
## 18Y
## 19Y
But I don't know how to add the index in list at the right place. The final DF would be :
Index Date
1D 9/13/2022
1W 9/19/2022
2W 9/26/2022
3W 10/3/2022
1M 10/12/2022
2M 11/14/2022
3M 12/12/2022
4M 1/12/2023
5M 2/13/2023
6M 3/13/2023
7M 4/12/2023
8M 5/12/2023
9M 6/12/2023
10M 7/12/2023
11M 8/14/2023
12M 9/12/2023
18M 3/12/2024
2Y 9/12/2024
3Y 9/12/2025
4Y 9/14/2026
5Y 9/13/2027
6Y 9/12/2028
7Y 9/12/2029
8Y 9/12/2030
9Y 9/12/2031
10Y 9/13/2032
11Y NA
12Y 9/12/2034
13Y NA
14Y NA
15Y 9/14/2037
16Y NA
17Y NA
18Y NA
19Y NA
20Y 9/12/2042
if int(self.dfcurve.index[i+1][:-1])-int(self.dfcurve.index[i][:-1])!= 1:Note thatint(self.dfcurve.index[i][:-1])delete the last char so we have only the number, and then we have to check if for example 3-2 = 1 ect.. if it is not add values.