1

I have result of hourly price by using group by:

group=df.groupby("hour")["price"].mean()

and then I normalize the result by max price by using this code:

nor=preprocessing.normalize(group, norm='max')

I then plot the result using this code:

plt.figure()

plt.plot( nor,
        label='price 1',
        color='red')
plt.xlim(0,24)
plt.ylim([0.0, 1])
plt.xlabel('time')
plt.ylabel('price')
plt.title('g2')
plt.legend(loc='upper right', fancybox=True)

plt.show()

but it does not show anything?

1
  • Your question is a little unclear on whether you get errors or just no plot. Are you in a notebook? Did you invoke %pylab inline? Commented Mar 23, 2017 at 6:20

1 Answer 1

1

I think you need convert one-line 2D array to 1D array, but first need reshape by reshape(1, -1) because Series group is converted to a single sample:

nor=preprocessing.normalize(group.values.reshape(1,-1), norm='max')[0,:]

Another solution with numpy.squeeze:

nor=np.squeeze(preprocessing.normalize(group.values.reshape(1,-1), norm='max'))

Another alternatives are here.

Sample:

np.random.seed(100)
df = pd.DataFrame({'hour':range(24),
                   'price':np.random.random(size=24)})

#print (df)

group=df.groupby("hour")["price"].mean()
nor=preprocessing.normalize(group.values.reshape(1,-1), norm='max')[0,:]
print (nor)
[ 0.55527461  0.28444985  0.43379039  0.86322869  0.00482193  0.12422457
  0.68540035  0.84389197  0.13969269  0.58765517  0.91079122  0.21377175
  0.18937637  0.11074418  0.22449638  1.          0.82941286  0.17569674
  0.83405366  0.28006038  0.44113396  0.96056302  0.83550941  0.34345369]

plt.figure()

plt.plot( nor,
        label='price 1',
        color='red')
plt.xlim(0,24)
plt.ylim([0.0, 1])
plt.xlabel('time')
plt.ylabel('price')
plt.title('g2')
plt.legend(loc='upper right', fancybox=True)

plt.show()

graph

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.