Python Forum
Newbie question to return only the index of a dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie question to return only the index of a dataframe
#1
import datetime
import numpy as np
import pandas as pd

def get_index(df, offset):
    print(df.iloc[offset:df.index.max(), 0:0])
    return (df.iloc[offset:df.index.max(), 0:0])

data={'id': [0,1,2,3], 'A':[1.1, 1.2, 1.3, 1.4]}
df0=pd.DataFrame(data)
df1=df0.set_index('id')
idx1 = get_index(df1, 1)
print('idx1 = ', idx1)    
I have a simple dataframe, I want to write a function to return only a part of index.
But my code did NOT work, the result is empty dataframe.
How I can reach my goal?
Please advise.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interpolating DataFrame method=‘index’ help tlewick1 1 122 Oct-22-2020, 12:48 AM
Last Post: scidam
  Python & Dataframe basic question georgialtr 0 784 Apr-06-2020, 03:59 PM
Last Post: georgialtr
  newbie: loop, modify dataframe cells expat_th 5 519 Mar-03-2020, 09:05 PM
Last Post: jefsummers
  Getting Index Error - list index out of range RahulSingh 2 1,226 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  How to find index of a particular value in a dataframe ankitawadhwa 0 505 Jan-21-2020, 09:45 PM
Last Post: ankitawadhwa
  How to add data to the categorical index of dataframe as data arrives? AlekseyPython 1 587 Oct-16-2019, 06:26 AM
Last Post: AlekseyPython
  Applying operation to a pandas multi index dataframe subgroup Nuovoq 1 848 Sep-04-2019, 10:04 PM
Last Post: Nuovoq
  How to return values from For Loop via return in a function AykutRobotics 14 2,673 Jan-08-2019, 04:12 AM
Last Post: stullis
  Simple pandas dataframe question popohoma 1 984 Jan-03-2019, 05:00 PM
Last Post: ashlardev
  How to get first and last row index of each unique names in pandas dataframe SriRajesh 1 2,241 Oct-13-2018, 07:04 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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