I import only two columns from the .xlsx file, and I would like to calculate some things (average value, deviation, percentage change), and then I would like to build it all. The first part does not give me any problems, but the construction does.
My code is as follows:
import matplotlib.pyplot as plt import numpy as np import pandas as pd import matplotlib.mlab as mlab import math df = pd.read_excel('KDPrviIzbor.xlsx', sheetname='List1', index_col = 0) ch = df.pct_change(periods=252) ma = np.mean(ch)*100 std = np.std(ch)*100 x = np.linspace(-100,100,500) plt.plot(x,mlab.normpdf(x,ma,std)) plt.show()
But when I run my code, I get this error:
Traceback (most recent call last): File "C:/Users/David/PythonStuff/normal_distribution.py", line 21, in <module> plt.plot(x,mlab.normpdf(x,ma,std)) File "C:\Python27\lib\site-packages\matplotlib\mlab.py", line 1579, in normpdf return 1./(np.sqrt(2*np.pi)*sigma)*np.exp(-0.5 * (1./sigma*(x - mu))**2) File "C:\Python27\lib\site-packages\pandas\core\ops.py", line 534, in wrapper dtype=dtype) File "C:\Python27\lib\site-packages\pandas\core\series.py", line 220, in __init__ data = SingleBlockManager(data, index, fastpath=True) File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 3383, in __init__ ndim=1, fastpath=True) File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 2101, in make_block placement=placement) File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 77, in __init__ len(self.values), len(self.mgr_locs))) ValueError: Wrong number of items passed 500, placement implies 1`
I realized that the problem is this:
plt.plot(x,mlab.normpdf(x,ma,std))
but I canβt solve it. Any suggestions?