0
votes
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. 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.

Here pictures of the graphics

1

right graphic (the one i should get)

2

the one i get with data.variacion.plot(kind="hist")

Thanks a lot and sorry for my bad english. :)

1
always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. - furas
what book do you use? How old is this book? Put some example data in code so we could run it and test problem. - furas
I would like to share the file but i dont know if i can. Its an xlsx file with information of the AAPLs share in the stock market, so i have thousands of lines. I wouldnt know which part to give you for using it as an example. And the book is new, they guy just published it this year - Emiliano Toffoli
don't share file but put some example data directly in code. df = pd.DataFrame(...) - furas

1 Answers

0
votes

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")