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 tr
You can also do as a convenience:
df[:10]
dataframe[:n] - Will return first n-1 rows
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.head.html?highlight=head#pandas.DataFrame.head
df2 = df.head(10)
should do the trick
df.ix[10,:]
gives you all the columns from the 10th row. In your case you want everything up to the 10th row which is df.ix[:9,:]
. Note that the right end of the slice range is inclusive: http://pandas.sourceforge.net/gotchas.html#endpoints-are-inclusive
I can see at least three options:
1.
df[:10]
2. Using head
df.head(10)
For negative values of n, this function returns all rows except the last n rows, equivalent to
df[:-n]
[Source].
3. Using iloc
df.iloc[:10]