python - pandas dataframe: meaning of .index -


i trying understand meaning of output of following code:

import pandas pd  index = ['index1','index2','index3'] columns = ['col1','col2','col3'] df = pd.dataframe([[1,2,3],[1,2,3],[1,2,3]], index=index, columns=columns) print df.index 

i expect list containing index of dataframe:

['index1, 'index2', 'index3']

however output is:

index([u'index1', u'index2', u'index3'], dtype='object')

this pretty output of pandas.index object, if @ type shows class type:

in [45]: index = ['index1','index2','index3'] columns = ['col1','col2','col3'] df = pd.dataframe([[1,2,3],[1,2,3],[1,2,3]], index=index, columns=columns) df.index  out[45]: index(['index1', 'index2', 'index3'], dtype='object')  in [46]: type(df.index)  out[46]: pandas.indexes.base.index 

so shows have index type elements 'index1' , on, dtype object str

if didn't pass list of strings index default int index new type rangeindex:

in [47]: df = pd.dataframe([[1,2,3],[1,2,3],[1,2,3]], columns=columns) df.index  out[47]: rangeindex(start=0, stop=3, step=1) 

if wanted list of values:

in [51]:     list(df.index)  out[51]: ['index1', 'index2', 'index3'] 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -