I am writing the following code, and I want to get only the first 3 minutes of the values with
pd.where method, but I get the following error:
ValueError: Array conditional must be same shape as self
import pandas as pd import numpy as np index = pd.date_range(start = '2017-06-01 00:00', end='2017-06-01 01:00', freq='1min') values = np.arange(0, len(index)) df = pd.DataFrame(values, index = index) df.where(df.index <= df.index + pd.DateOffset(minutes=3), np.nan)
There is an another question with this error but the contexts are different.
The code for integer index seems to work well, but for time series I have problem.