I am running Pandas 0.20.3 with Python 3.5.3 on macOS.
I have a multiindexed dataframe similar to the following df
:
import pandas as pd
import numpy as np
refs = ['A', 'B']
dates = pd.date_range(start='2018-01-01', end='2018-12-31')
df = pd.DataFrame({'ref': np.repeat(refs, len(dates)),
'date': np.tile(dates, len(refs)),
'value': np.random.randn(len(dates) * len(refs))})
df.set_index(["ref", "date"], inplace=True)
I want to modify the dataframe and set some values to 0. Say where ref
is equal to 'A' and where date is before 2018-01-15.
I am using the following:
df.loc["A"].loc[df.loc["A"].index < pd.to_datetime('2018-01-15')] = 0
I do not get any SettingWithCopyWarning
and the dataframe is modified correctly on my mac. However when I run this code on a Windows environment with the same pandas version, the dataframe is not modified.
Hence my question: Is the above code incorrect? If not, how to properly make the assignment I need?