If you want this ipcaMomSlice
to be it's own entity, and not refer back to ipcaMom
(e.g. you don't want to assign a "multiplier" column to ipcaMom
at all, and only want the "multiplier" on ipcaMomSlice
) you'll need to tell pandas that ipcaMomSlice
is no longer just a slice of a dataframe, but a full on independent subset. This is done with the .copy()
method.
import pandas as pd
ipcaMom = bcbQuery(433)
ipcaMom['valor'] /= 100
initDate = "1995-01-01"
ipcaMomSlice = ipcaMom[initDate:].copy()
# no need for `.loc` in this assignment operation
ipcaMomSlice['multiplier'] = (1 + ipcaMomSlice['valor']).cumprod()
If however you're expecting "multiplier" to magically appear as a column in ipcaMom
you'll need to combine your indexing from your .loc
import pandas as pd
ipcaMom = bcbQuery(433)
ipcaMom['valor'] /= 100
initDate = "1995-01-01"
ipcaMom.loc[initdate:, 'multiplier'] = (1 + ipcaMom.loc[initdate:, 'valor']).cumprod()