2016-07-25 8 views
0

の意味、私は次のコードの出力の意味を理解しようとしています:パンダのデータフレーム:.INDEX

import pandas as 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 

私はデータフレームのインデックスを含むリストだけを期待する:

[ '出力がしかし]

インデックス([u'index1 '' index1の 'INDEX2'、' index3、u'index2' 、u'index3 ']、DTYPE =' オブジェクト ')

答えて

0

これは、あなたがタイプを見れば、それはクラス型を示し、pandas.Indexオブジェクトのかなり出力されます:

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 

だから何それは示しすることは、要素の値index1 'でIndexタイプを持っているということで、その上、DTYPEはあなたが新しいタイプRangeIndexでデフォルトのint型のインデックスを取得インデックスの文字列のリストを通過しなかった場合str

あるobjectです:

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) 

あなたは、値のリストたい場合:

In [51]:  
list(df.index) 

Out[51]: 
['index1', 'index2', 'index3'] 
+0

をDTYPEは「オブジェクト」とない(などSTR、リスト、など)より具体的なものであるのはなぜ? – qstax

+0

これは 'numpy'のものです:http://docs.scipy.org/doc/numpy/reference/arrays.scalars.htmlだから基本的な型ではないので、' dtype'がどのように表現されているのですか? float、datetime、category、str、lists、dicts、setsはすべて 'object'にまとめられます – EdChum

関連する問題