我有一个熊猫系列测试集y_test。我想知道它的大小用于统计。
使用此代码:
print(y_test.shape)
我
(31054,)
我想要得到31054
你可以选择
size = y_test.shape[0]
返回元组的第一个元素,即size。也可以直接使用size
属性或len()
方法获取。
size = y_test.size
#or
size = len(y_test)
y_test.shape
给出一个元组。所以你可以执行print(y_test.shape)[0]
来获取第一个元素,也就是序列的大小。
shape
给了你一个元组,因为它来自dataframes, dataframes给了你帧的形状(行,列)。
使用len
或Series.size
:
y_test = pd.Series(range(20))
print(len(y_test))
20
print(y_test.size)
20