0

I have been doing some reading from fer 2013 csv file containing three columns emotion, pixel value and usage. the pixel value is said to have given in string format and I want to rescale my pixel values from 0-255 to between 0-1 , so I need to convert it to int/float and then only I would be able to do any mathematical operations on them.

I first tried to read the csv file using pandas read_csv function and then using iloc I read the value of the pixel value in a variable called x_tr. Then upon printing its value it shows its d type as object.confused on that too.x_tr is numpy ndarray then how should I convert it into integral value. I tried the x_tr.astype(np.float) but it gave up the error as mentioned in the code.

x_tr = train.iloc[:,1].values
x_tr

The screenshot of what x_tr contains

what I tried to convert to float

x_tr = train.iloc[:,1].values
x_tr = x_tr.astype(np.float) 

and what I've got as error

enter image description here

Please Help.

2
  • They are from a set of 28k images with each image being a size of 48*48 how could I post them as code?? Commented Apr 20, 2019 at 10:25
  • Post a sample; otherwise, how can we reproduce your issue and offer concrete advice? Commented Apr 20, 2019 at 10:26

1 Answer 1

1

Don't convert your pixel into an array, instead treat it as a simple string. Then use numpy.fromstring() method. Here's an example for reference.

>>> s = '1 2 3 4'
>>> f = np.fromstring(s, dtype=float, sep=' ')
>>> f
array([1., 2., 3., 4.])
Sign up to request clarification or add additional context in comments.

Comments

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.