如何按位置切片 pandas 数据框? [英] How to slice a Pandas Data Frame by position?

查看:57
本文介绍了如何按位置切片 pandas 数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有1000行和10列的Pandas Data Frame对象.我只想对数据框进行切片,并获取前10行.我怎样才能做到这一点?我一直在尝试使用:

I have a Pandas Data Frame object that has 1000 rows and 10 columns. I would simply like to slice the Data Frame and take the first 10 rows. How can I do this? I've been trying to use this:

>>> df.shape
(1000,10)
>>> my_slice = df.ix[10,:]
>>> my_slice.shape
(10,)

my_slice不应是前十行,即. 10 x 10数据帧?如何获得前十行,例如my_slice是10x10数据帧对象?谢谢.

Shouldn't my_slice be the first ten rows, ie. a 10 x 10 Data Frame? How can I get the first ten rows, such that my_slice is a 10x10 Data Frame object? Thanks.

推荐答案

应该可以解决问题

这篇关于如何按位置切片 pandas 数据框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆