我的数据框形状(199,7)。我想选择列0:4和-2:(最后两列)。我想得到[final_data['unemployed']=='yes']
所选列的行。我的专栏是
['panicattacks', 'compulsivebehavior', 'depression', 'anxiety','tiredness', 'unemployed', 'cluster']
ValueError: special directives must be the first entry
李>final_data[np.r_[final_data.columns[0:4],final_data.columns[2]]][final_data['unemployed']=='yes']
final_data.iloc[:,np.r_[0:4,-2:]][final_data['unemployed']=='yes']
他们为什么不工作?我该怎么做
这是一种生成错误消息的表达式。我在你的样品中没有看到:
在更简单的上下文中测试
r_
:及
我不太确定你想要什么第二档。请记住,使用
r_
时,负值范围很棘手,r_
不知道df.columns
的大小编辑
[154]
之所以有效,是因为我的示例数据帧具有数字列标题。将其更改为字符串:引起错误的是
r_
:问题是第一个参数,一个字符串数组:
看起来最简单的解决方法是使用}r}r}的`切片特殊处理:
hstack
(或者只是“连接) instead of
r{相关问题 更多 >
编程相关推荐