Python:将具有1列的数据框转换为特定的ndarray

时间:2020-11-11 09:29:01

标签: python python-3.x pandas numpy numpy-ndarray

我有1列n行的pandas数据框,例如:

curry

我使用 to_numpy()函数将此数据帧转换为ndarray,但得到了ndarray:

enter image description here

我想要一个像这样的ndarray: 0 0 03110311000311 1 18003130313000313 2 36003120312000312 3 54003110311000311 4 72003100310000310 ... ... [1400 rows x 1 columns]

该怎么办?谢谢!

1 个答案:

答案 0 :(得分:0)

只需首先选择该列:

df['column_index'].to_numpy()

示例:

df = pd.DataFrame(np.arange(6))

df.to_numpy().shape            # (6,1)

df[0].to_numpy().shape       # (6,)
相关问题