I'm manually filling up some categorical labels in a column which is is_holiday
. There are rows that have only the first observation with the correct label, the rest are 0 and I'm filling these zeros:
# Before filling
print(main_data.loc["25 December, 2012"].is_holiday)
date_time
2012-12-25 00:00:00 3
2012-12-25 01:00:00 0
2012-12-25 02:00:00 0
2012-12-25 03:00:00 0
.
.
.
2012-12-25 19:00:00 0
2012-12-25 20:00:00 0
2012-12-25 21:00:00 0
2012-12-25 22:00:00 0
2012-12-25 23:00:00 0
Name: is_holiday, dtype: int64
# Manually fill
for row in range(len(main_data.loc["2012"])):
if main_data.Month[row] == 12 and main_data.Day[row] == 25:
if main_data.is_holiday[row] == 0:
main_data.is_holiday[row] = 3 # 3 is label for Xmas
# After filling
print(main_data.loc["25 December, 2012"].is_holiday)
2012-12-25 00:00:00 3
2012-12-25 01:00:00 3
2012-12-25 02:00:00 3
2012-12-25 03:00:00 3
.
.
.
2012-12-25 19:00:00 3
2012-12-25 20:00:00 3
2012-12-25 21:00:00 3
2012-12-25 22:00:00 3
2012-12-25 23:00:00 3
Name: is_holiday, dtype: int64
However, if I execute the same code for another year, say 2013, the values remain the same. I tried modifying the code including minor changes but the holiday labels won't change:
# Before filling
print(main_data.loc["25 December, 2013"].is_holiday)
date_time
2013-12-25 00:00:00 3
2013-12-25 01:00:00 0
2013-12-25 02:00:00 0
2013-12-25 03:00:00 0
.
.
.
2013-12-25 19:00:00 0
2013-12-25 20:00:00 0
2013-12-25 21:00:00 0
2013-12-25 22:00:00 0
2013-12-25 23:00:00 0
Name: is_holiday, dtype: int64
# Manually fill
for row_2 in range(len(main_data.loc["2013"])):
if main_data.Month[row_2] == 12 and main_data.Day[row_2] == 25:
if main_data.is_holiday[row_2] == 0:
main_data.is_holiday[row_2] = 3 # 3 is label for Xmas
# After filling
print(main_data.loc["25 December, 2013"].is_holiday)
2013-12-25 00:00:00 3
2013-12-25 01:00:00 0
2013-12-25 02:00:00 0
2013-12-25 03:00:00 0
.
.
.
2013-12-25 19:00:00 0
2013-12-25 20:00:00 0
2013-12-25 21:00:00 0
2013-12-25 22:00:00 0
2013-12-25 23:00:00 0
Name: is_holiday, dtype: int64
What am I missing here? I did not expect this to happen. It works as expected for some holidays while it won't for others. Please do keep in mind that Month
and Day
are separate columns that I have engineered in main_data
.
Edit: I'm welcome to better methods for achieving this.