我有pandas.DataFrame
,我只对最后一列的值感兴趣。Handeling在熊猫中的特定列的形状
np.shape(dataframe.iloc[:,:]) # the output is (2190,460)
# Now here is the shape of one cell in the last column
np.shape(dataframe.iloc[0,-1]) # the output is (20,)
dataframe.iloc[0,-1] # the output [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
我的问题是如何能得到此列保存在以下形态:(2190, 20)
自运行:
np.shape(dataframe.iloc[:,-1]) # the output (2190,)
而这种形状使用造成了我一个巨大的问题
解决方案loop:
Test_Labels = []
for i in range(len(dataframe)):
Test_Labels.append(dataframe.iloc[i,-1])
np.shape(Test_Labels)
如果有人能用熊猫功能解决它,很高兴看到它。
'数据帧[dataframe.columns [-1]' –
@StephenRauch你测试? – Engine
在一个小的(2x2)数据帧上。 –