因此,我正在建立模型并尝试使用|换一个新专栏,我对自己做错了感到困惑。如果值为true,则应该创建一个新列并键入1。
例如,这有效:
feature_matrix["After 2016"] = (feature_matrix.index.year > 2016).astype(int)
但是,这没有做任何事情:
feature_matrix["Summer"] = (feature_matrix.index.month == 6|7|8|9).astype(int)
当我尝试使用相同的方法在周末做同样的事情。
我尝试使用解决它:
feature_matrix["Summer"] = (feature_matrix.index.month == 6| feature_matrix.index.month == 7).astype(int)
但这给了我:|:'int'和'Int64Index'的不受支持的操作数类型
We have
isin
Yoben's answer is correct and complete, but a note:
6|7|8\9
is always true, and unless you have True in your column, this will do nothing.