[英]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")
我正在从一本书中学习,它在 jupyter 中编写了编码脚本,最后的图形行是我在上面写的。 在尝试执行时,我遇到了以下问题:
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'
如果我删除.loc[data.index>"2019-01-01"]
我得到一个图形但不是正确的。
这里是图形的图片
正确的图形(我应该得到的那个)
我用data.variacion.plot(kind="hist")
得到的那个
非常感谢,很抱歉我的英语不好。 :)
试试这个:
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.