如何将熊猫系列或索引转换为Numpy数组?您知道如何将DataFrame的索引或列作为NumPy数组或python列表吗?
3 回答

德玛西亚99
TA贡献1770条经验 获得超3个赞
values
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c']); df A B a 1 4b 2 5c 3 6In [2]: df.index.valuesOut[2]: array(['a', 'b', 'c'], dtype=object)
In [3]: df['A'].valuesOut[3]: Out[16]: array([1, 2, 3])
tolist
:
In [4]: df.index.tolist()Out[4]: ['a', 'b']

泛舟湖上清波郎朗
TA贡献1818条经验 获得超3个赞
df.index
df.index.tolist()
df['col'].tolist()
添加回答
举报
0/150
提交
取消