我有一个熊猫据帧称为df哪里df.shape是(53, 80)哪里的索引和列都是int。如果选择这样的第一行,则会得到:df.loc[0].shape(80,)代替 :(1,80)但是然后df.loc[0:0].shape或df[0:1].shape两者都显示正确的形状。
2 回答

烙印99
TA贡献1829条经验 获得超13个赞
调用时df.iloc[0],它选择的是第一行,类型是,Series而在其他情况下,df.iloc[0:0]它是对行进行切片,并且是type dataframe。并且Series根据pandas系列文档:
带轴标签的一维ndarray
而dataframe是二维(熊猫数据帧的文档)。
尝试运行以下几行以查看区别:
print(type(df.iloc[0]))
# <class 'pandas.core.series.Series'>
print(type(df.iloc[0:0]))
# <class 'pandas.core.frame.DataFrame'>
添加回答
举报
0/150
提交
取消