0

hallo sorry for my bad English, I want to convert my pixels column to separated numpy array for every row (if read using pandas dataframe it columns values will be read as array). this is example of my dataset, I have tried split every row of pixels for every space, but because of the dataset is about 35.000 data and the pixels value are long, so the pandas going error

target, pixels

0, 12 14 14 16 29 30 29 39 50 60 12 10 0 29 40 14

1, 13 15 15 17 25 32 23 31 59 62 17 19 1 22 20 20

2, 12 16 16 18 32 33 22 45 23 12 12 10 2 50 45 13

to (if read by dataframe)

target, pixels

0, array[12,14,14,16,29,29,39,50,60,12,10,0,29,40,14]

1, array[13,15,15,17,25,32,23,31,59,62,17,19,1,22,20,20]

2, array[12,16,16,18,32,33,22,45,23,12,12,10,2,50,45,13]

5
  • I'm not so clear about your question. You want every row as an separate array? like: array1: [12, 14, 14, ...], array2: [13, 15, 15,...], am I right? Commented Mar 18, 2019 at 3:53
  • yep you're right Commented Mar 18, 2019 at 3:56
  • what is the datatype of your pixel column? Commented Mar 18, 2019 at 4:58
  • @Adji I think this will help you stackoverflow.com/questions/19574258/… Commented Mar 18, 2019 at 5:05
  • @bumblebee it's a string Commented Mar 18, 2019 at 5:56

2 Answers 2

1

There maybe other methods that is more memory efficient, but I came up with a simple solution like this:

l = [] # this will be a storage list for your array
for n, row in enumerate(df.index):
    df.iloc[row, :] = l[n]

Then you can access the separated array in the list l

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much I'll try it
1

Not very much clear on your question, but hope below suggestion will help,

Try to convert the column in matrix --load it into a numpy array and reshape it so that it is in desired dimensional

I think for image pixle data, Digit Recognizer problem on MNIST data is very helpful Give a look to kaggle kernal

[https://www.kaggle.com/aman9d/digit-recognizer-svm-88-3-data-visualization/data][1]

1 Comment

Thank you so much!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.