I would like to 'link' two pieces of code. One,
x= df[df['Value']==True].sort_values(by='Date').head(1).Date
Out[111]:
8 2020-03-04
extracts the date where the first value appears; the other one
df[df['Buy']==1].groupby('Date').size().plot(ax=ax, label='Buy')
should plot some information through time.
I would like to add a vertical line at the first date where the value is true, i.e. 2020-03-04
. In order to do it, I would need to extract this information from the first code (not using copy and paste) to the other piece of code which generates the plot.
Can you give me some guide on how to do it? Thanks a lot
Update:
I tried as follows:
x= df[df['Value']==True].sort_values(by='Date').head(1).Date.tolist()
Out[111]:
8 ['2020-03-04']
df[df['Buy']==1].groupby('Date').size().plot(ax=ax, label='Buy')
ax.axvline(x, color="red", linestyle="--")
but I got a TypeError: unhashable type: 'numpy.ndarray'
Some data:
Date Buy Value
0 2020-02-23 0 False
1 2020-02-23 0 False
2 2020-02-25 0 False
3 2020-02-27 1 False
4 2020-03-03 1 False
5 2020-03-03 1 False
6 2020-03-03 0 False
7 2020-03-04 1 False
8 2020-03-04 0 True
9 2020-03-04 0 True
10 2020-03-04 1 False
11 2020-03-05 0 True
12 2020-03-05 1 False
13 2020-03-05 1 False
14 2020-03-05 1 False
15 2020-03-06 0 False
16 2020-03-06 1 False
17 2020-03-06 1 False
18 2020-03-07 1 False
19 2020-03-07 1 False
20 2020-03-07 1 False
21 2020-03-08 1 False
22 2020-03-08 1 False
23 2020-03-09 1 False
24 2020-03-09 1 False
25 2020-03-09 1 False
26 2020-03-10 1 False
27 2020-03-10 1 False
28 2020-03-10 1 False
29 2020-03-10 0 True
30 2020-03-11 1 False
31 2020-03-11 1 False
32 2020-03-13 0 True
33 2020-03-13 0 False
34 2020-03-15 0 True
35 2020-03-16 0 False
36 2020-03-19 0 False
37 2020-03-22 0 True