Here I have a dataset with three inputs. Here I generated y value using append. After the append I got the output like this:


enter image description here

Then I tried to develop neural network model with these values. Before that I tried to scale the y value. my code:

y =y.values().astype(int)
scaler_y = preprocessing.MinMaxScaler(feature_range =(0, 1))
y = np.array(y).reshape([-1, 1])
y = scaler_y.fit_transform(y)

Then I got an error :

AttributeError                            Traceback (most recent call last)
<ipython-input-254-2ec9d2fcbffd> in <module>()
----> 1 y = y.values().astype(int)

 AttributeError: 'list' object has no attribute 'values'

Can anyone help me to solve this error?


It is basically what the error message says. The problem is this:

y =y.values().astype(int)

y is a list and lists do not have a method values() (but dictionaries and DataFrames do).

If you would like to convert y to a list of integers you can use list comprehension:

y = [int(x) for x in y]

Or alternatively use map (but I'd prefer the list comprehension):

y = list(map(int, y))

Since this is actually a coding related question you might want to consider posting on https://stackoverflow.com next time.

| improve this answer | |
  • $\begingroup$ sorry this code gave me this error "invalid literal for int() with base 10: 'date'" $\endgroup$ – bala Nov 14 '19 at 8:41
  • $\begingroup$ int() can convert string representations of integers and floats to integers. But it looks like you are trying to convert something else to integer. Can you show what exactly y contains? $\endgroup$ – Sammy Nov 15 '19 at 10:19
  • $\begingroup$ y is contain with date and value together. (date (2018-06-18 06:15:00 ) 141) $\endgroup$ – bala Nov 17 '19 at 16:10
  • $\begingroup$ You cannot convert a datetime with int(). Instead you need to call timestamp() on the datetime which gives you a float value in seconds. As long as you do not have anything smaller than seconds you can convert that to integer: y = [int(i.timestamp()) for i in y] works if y contains only entries of type datetime. However, this will not work as long as y is a mix of datetime and some other values. Can you explain what you are trying predict here and why it is a mix of datetime and other numbers? $\endgroup$ – Sammy Nov 17 '19 at 23:09
  • $\begingroup$ first of all i will explain my csv file. Here I have three inputs with datetime. Here I measured value not in exact time per hour. It is jumbled. So first what I did , make all data to display with in every one hour. After writing that code, it is displayed in evry hour data as above. then the data is append value mix with datetime. Then according to that data I want to predict value. This is what I am trying to do ? $\endgroup$ – bala Nov 18 '19 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.