0
我正在编写下面的代码,并且我只想用pd.where
方法获取值的前3分钟,但出现以下错误: ValueError:数组条件必须是相同的形状,自当在熊猫中使用DataFrame.where方法时出现ValueError
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[0] + pd.DateOffset(minutes=3), np.nan)
没有与此误差的another question但是上下文是不同的。
整数索引的代码似乎运作良好,但对于时间序列我有问题。