I am trying to work out an effective date for any given date. The dataframe has a column which is populated by the BMonthEnd (last business day of month taking into account holidays - calculated by code not shown here)
the partial dataframe shown below has the EffectiveDate equal to the Date as 1st step
Date BMonthEnd EffectiveDate
2014-08-24 2014-08-24 2014-08-29 2014-08-24
2014-08-25 2014-08-25 2014-08-29 2014-08-25
2014-08-26 2014-08-26 2014-08-29 2014-08-26
2014-08-27 2014-08-27 2014-08-29 2014-08-27
2014-08-28 2014-08-28 2014-08-29 2014-08-28
2014-08-29 2014-08-29 2014-08-29 2014-08-29
2014-08-30 2014-08-30 2014-08-29 2014-08-30
2014-08-31 2014-08-31 2014-08-29 2014-08-31
I now try to select out the data that need to be changed with:
df[~(df.Date<df.BMonthEnd)].EffectiveDate # giving the expected slice
# but
df[~(df.Date<df.BMonthEnd)].EffectiveDate = 1
# gives error
SettingWithCopyWarning: A value is trying to be set on a copy of a slice
from a DataFrame. Try using .loc[row_index,col_indexer] = value instead
self[name] = value
following the warning i tried the alternate method i tried:
df.loc[~(df.Date<df.BMonthEnd)].EffectiveDate = 1
this also gives the same error. (note the 1 used in assignment is just placeholder for another function) and the assignment does not reflect on the original dataframe. I understand that I am effectively assigning to a copy so that it does not change the original dataframe as intended.
How do I however achieve my goal of using the selecting syntax to assign. I really do not want to have to iterate over the dataframe.
df['EffectiveDate']?