[英]Problem with a histogram graphic in python
import pandas as pd
import datetime as dt
data = pd.read_excel("d:/Documents/Python/Archivosejemplo/AAPL.xlsx")
data = data.sort_values(by="timestamp", ascending=True)
data["variacion"]=data.adjusted_close.pct_change()*100
data.loc[data.index>"2019-01-01"].variacion.plot(kind="hist")
I´m learning from a book, which does the coding scripts in jupyter, and the final graphic line of graphic is the one i write above.我正在从一本书中学习,它在 jupyter 中编写了编码脚本,最后的图形行是我在上面写的。 When trying to execute that i got the following problem:
在尝试执行时,我遇到了以下问题:
TypeError Traceback (most recent call last)
<ipython-input-2-9a9e22482642> in <module>
----> 1 data.loc[data.index>"2019-01-01"].variacion.plot(kind="hist")
~\anaconda3\lib\site-packages\pandas\core\indexes\base.py in cmp_method(self, other)
120 else:
121 with np.errstate(all="ignore"):
--> 122 result = op(self.values, np.asarray(other))
123
124 if is_bool_dtype(result):
TypeError: '>' not supported between instances of 'numpy.ndarray' and 'numpy.ndarray'
If i erase .loc[data.index>"2019-01-01"]
i got a graphic but not the correct one.如果我删除
.loc[data.index>"2019-01-01"]
我得到一个图形但不是正确的。
Here pictures of the graphics这里是图形的图片
right graphic (the one i should get)正确的图形(我应该得到的那个)
the one i get with data.variacion.plot(kind="hist")
我用
data.variacion.plot(kind="hist")
得到的那个
Thanks a lot and sorry for my bad english.非常感谢,很抱歉我的英语不好。 :)
:)
try whith this:试试这个:
import pandas as pd
data = pd.read_excel("AAPL.xlsx").set_index("timestamp")
data = data.sort_values("timestamp", ascending=True)
data["variacion"] = data.adjusted_close.pct_change()*100
data.loc[data.index>"2019-01-01"].variacion.plot(kind="hist")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.