luckyCasualGuy
luckyCasualGuy

Reputation: 691

Convert python pandas dataframe rows or columns into numpy array

I have a data frame like this. [from csv file]

       l1  p1 p2 p3 ... p10
    0   ↑  ←---- rows ----→
    1   |  ←---- rows ----→
    2   c  ←---- rows ----→
    3   o  ←---- rows ----→
    .   l  ←---- rows ----→
    .   |  ←---- rows ----→
    9   ↓  ←---- rows ----→

I want to convert l1 column into numpy array like this
[ ←, -, c, o, l, -, →] size : 10
and all the remaining columns into another numpy array like this\

[[ ← - r o w s - →],
 [ ← - r o w s - →],
 [ ← - r o w s - →]]    size: (10, 10)

Also


columns in the data frame are images so how can I further divide my data frame like this

           l1   p1 p2 .... p784
    0       ↑  ←---- rows ----→
    1       |  ←---- rows ----→
    2       c  ←---- rows ----→
    3       o  ←---- rows ----→
    .       l  ←---- rows ----→
    .       |  ←---- rows ----→
    27455   ↓  ←---- rows ----→

After getting the rows array on this data frame I will have numpy array of size(27455, 784) How to further split this array into size(27455, 28, 28)

how to do this !!
any other way will also be appreciated !!

Upvotes: 1

Views: 698

Answers (1)

BENY
BENY

Reputation: 323236

Try

col=df.l1.to_numpy()

ary=df.drop('l1',axis=1).to_numpy()

Upvotes: 2

Related Questions