Python Forum
Newbie question to return only the index of a dataframe - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: Data Science (https://python-forum.io/Forum-Data-Science)
+--- Thread: Newbie question to return only the index of a dataframe (/Thread-Newbie-question-to-return-only-the-index-of-a-dataframe)



Newbie question to return only the index of a dataframe - zydjohn - Jan-22-2018

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.