I am trying to append a data frame index if certain condition is met, apparently when I print the append everything is looking right and the code is working. But when I look at the data frame index after leaving the if there is no appended value in there even if the condition was met.
if (year_and_month not in to_dashboard.index):
print("I'm appending the index")
new_index = pd.Index([year_and_month])
print(new_index)
to_dashboard.index.append(new_index)
print(to_dashboard.index)
And there is the if output:
I am appending the index :
Index(['2022-08'], dtype='object')
Index(['2022-05', '2022-06', '2022-07'], dtype='object')