Python Forum
Pandas: .(head) Can I specify a range in head?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pandas: .(head) Can I specify a range in head?
#1
In pandas, is it possible to specify a range in head? for example say I want to view rows 10-20, is there something where I can do...

.head(10-20)
Reply
#2
print(df.iloc[10:21])
of course, don't forget index start at 0
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
this is what i have now...

sf.toPandas().head(20)

can you please help format what I should have?

Thank you
Reply
#4
post minimal reproducible example. I don't know what sf is? Probably sf.toPandas().iloc[10:21]
df common name for pandas.DataFrame
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
sorry about that. SF is the name of my data frame...its coming from pyspark and then I am moving the data in to pandas.

sf.toPandas().head(20)

Do you know who I would modify this line? Currently its giving me 20 rows but I would like to do within a range.

thank you
Reply
#6
(May-11-2020, 04:08 PM)buran Wrote: Probably sf.toPandas().iloc[10:21]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
sorry please ignore my previous post.. I saw your code above.

(May-11-2020, 04:26 PM)buran Wrote:
(May-11-2020, 04:08 PM)buran Wrote: Probably sf.toPandas().iloc[10:21]

it worked thank you!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  numpy.array has no attribute head Led_Zeppelin 1 1,276 Jul-13-2022, 12:56 AM
Last Post: Led_Zeppelin
  Cannot get output for df.head() Led_Zeppelin 0 1,095 Jun-28-2022, 02:15 PM
Last Post: Led_Zeppelin
  matplotlib x axis range goes over the set range Pedroski55 5 3,268 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Pyhton code help from head first with python Shaikat_99 3 3,201 Jun-07-2020, 09:12 AM
Last Post: snippsat
  Define a range, return all numbers of range that are NOT in csv data KiNeMs 18 7,130 Jan-24-2020, 06:19 AM
Last Post: KiNeMs
  Cant get my head round the algorithm hshivaraj 1 2,346 Apr-09-2019, 10:38 PM
Last Post: Yoriz
  invalid syntax in my program, really doing my head in! Fazz92 1 3,959 May-07-2017, 12:54 PM
Last Post: Bass

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020