2024-04-18 19:11:09 发布
网友
考虑一个行名本身不是列的数据帧,例如:
X Y Row 1 0 5 Row 2 8 1 Row 3 3 0
如果有索引,如何将这些行的名称提取为列表? 例如,它看起来像:
function_name(dataframe[indices]) > ['Row 1', 'Row 2']
看起来效果不错:
dataframe.axes[0].tolist()
df.index
Index
list(df.index)
df.index['Row 2':'Row 5']
如果只想提取某些基于整数的行索引的索引值,可以使用iloc方法执行如下操作:
iloc
In [28]: temp Out[28]: index time complete row_0 2 2014-10-22 01:00:00 0 row_1 3 2014-10-23 14:00:00 0 row_2 4 2014-10-26 08:00:00 0 row_3 5 2014-10-26 10:00:00 0 row_4 6 2014-10-26 11:00:00 0 In [29]: temp.iloc[[0,1,4]].index Out[29]: Index([u'row_0', u'row_1', u'row_4'], dtype='object') In [30]: temp.iloc[[0,1,4]].index.tolist() Out[30]: ['row_0', 'row_1', 'row_4']
看起来效果不错:
df.index
Index
对象。list(df.index)
df.index['Row 2':'Row 5']
如果只想提取某些基于整数的行索引的索引值,可以使用
iloc
方法执行如下操作:相关问题 更多 >
编程相关推荐