How to convert a pandas DataFrame subset of columns AND rows into a numpy array?

前端 未结 3 1644
野性不改
野性不改 2020-12-04 10:31

I\'m wondering if there is a simpler, memory efficient way to select a subset of rows and columns from a pandas DataFrame.

For instance, given this dataframe:

<
3条回答
  •  天命终不由人
    2020-12-04 11:01

    Use its value directly:

    In [79]: df[df.c > 0.5][['b', 'e']].values
    Out[79]: 
    array([[ 0.98836259,  0.82403141],
           [ 0.337358  ,  0.02054435],
           [ 0.29271728,  0.37813099],
           [ 0.70033513,  0.69919695]])
    

提交回复
热议问题