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
  [split] Getting Index Error - list index out of range krishna 2 2,603 Jan-09-2021, 08:29 AM
Last Post: buran
  Interpolating DataFrame method=‘index’ help tlewick1 1 1,840 Oct-22-2020, 12:48 AM
Last Post: scidam
  Python & Dataframe basic question georgialtr 0 3,860 Apr-06-2020, 03:59 PM
Last Post: georgialtr
  newbie: loop, modify dataframe cells expat_th 5 3,694 Mar-03-2020, 09:05 PM
Last Post: jefsummers
  Getting Index Error - list index out of range RahulSingh 2 6,142 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  How to find index of a particular value in a dataframe ankitawadhwa 0 2,377 Jan-21-2020, 09:45 PM
Last Post: ankitawadhwa
  How to add data to the categorical index of dataframe as data arrives? AlekseyPython 1 2,339 Oct-16-2019, 06:26 AM
Last Post: AlekseyPython
  Applying operation to a pandas multi index dataframe subgroup Nuovoq 1 2,644 Sep-04-2019, 10:04 PM
Last Post: Nuovoq
  How to return values from For Loop via return in a function AykutRobotics 14 8,253 Jan-08-2019, 04:12 AM
Last Post: stullis
  Simple pandas dataframe question popohoma 1 3,540 Jan-03-2019, 05:00 PM
Last Post: ashlardev

Forum Jump:

User Panel Messages

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