我想根据dtype选择列。 例子:
<TextBox AcceptsReturn="False">
<TextBox.InputBindings>
<KeyBinding
Key="Enter"
Command="{Binding SearchCommand}"
CommandParameter="{Binding Path=Text, RelativeSource={RelativeSource AncestorType={x:Type TextBox}}}" />
</TextBox.InputBindings>
uints的预期输出为:[10,11,12,13,14,15,16,17,18,19] 问题是当我使用hstack将原始numpy数据(a和b)连接在一起时,无法正确检测到dtype,因为上面的代码返回[]。
答案 0 :(得分:0)
我认为pandas可以更好地处理不同的数据类型。试试这个:
# Converting your arrays to dataframes
a = pd.DataFrame(np.random.randn(10, 10).astype('float'))
b = pd.DataFrame(np.random.randn(10, 10).astype('uint8'))
df = pd.concat([a,b],axis=1) # horizontally concatenating a and b
df.columns=[i for i in range(20)] # setting the column names manually
print(df.head())
0 1 2 3 4 5 6 \
0 0.931404 0.612939 -0.369925 -0.777209 0.776831 1.923639 0.714632
1 1.002620 0.612617 -0.184530 -0.279565 -0.021436 1.079653 0.299139
2 0.938141 0.621674 1.723074 0.298568 -0.892739 -1.154118 -2.623486
3 -1.050390 -1.058590 1.319297 -1.052302 -0.633126 -1.089275 0.796025
4 -0.312114 -0.045124 -0.094495 0.296262 0.518496 0.068003 -1.247959
7 8 9 10 11 12 13 14 15 16 17 18 19
0 0.710094 -1.465146 -0.009591 0 255 0 255 0 0 0 0 0 1
1 1.645174 -0.491199 0.961290 0 253 0 1 254 1 0 255 0 0
2 0.633076 -1.366998 -0.450123 0 1 255 255 0 0 255 0 254 0
3 -0.650617 1.226741 1.884750 0 255 0 0 0 0 255 0 1 0
4 -0.774224 0.780239 -1.072834 0 254 3 2 0 0 0 0 0 0
df.select_dtypes(include=['uint8']).columns.tolist()
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]