[英]Extract numpy arrays from pandas dataframe as matrix
I ended up with the following data structure: 我最终得到以下数据结构:
import numpy as np
import pandas as pd
my_df = pd.DataFrame({'col_1': [1,2,3]})
my_df['col_1'] = my_df['col_1'].apply(lambda x: np.array([1,2,3]))
my_df.as_matrix()
it looks like this: 它看起来像这样:
array([[array([1, 2, 3])],
[array([1, 2, 3])],
[array([1, 2, 3])]], dtype=object)
Whily I would like it to look like simply numpy matrix. 我希望它看起来像仅仅是numpy矩阵。 Any thoughts?
有什么想法吗?
If you just want an array, you can 如果只需要一个数组,可以
np.array(my_df.col_1.tolist())
array([[1, 2, 3],
[1, 2, 3],
[1, 2, 3]])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.