Indexing by Time Enter Data by Adjusting the Year
I'm studying python where the confusion is to make it by year, I really ask for help, I have stock data like this (data1) data from yfinance
data1 = yf.download(ticker,'2000-01-01','2021-01-01')
with the contents of the (data1)
Index(['Open', 'High', 'Low', 'Close', 'Adj Close', 'Volume'], dtype='object')
.
Date Open High Low Close* Adj Close** Volume
04/01/2011 15:00:00 4,330.00 4,390.00 4,300.00 4,390.00 4,390.00 186,370,900
05/01/2011 15:00:00 4,260.00 4,290.00 4,210.00 4,280.00 4,280.00 128,905,400
06/01/2011 15:00:00 4,280.00 4,300.00 4,160.00 4,200.00 4,200.00 116,634,000
07/01/2012 15:00:00 4,300.00 4,300.00 4,240.00 4,270.00 4,270.00 97,239,100
08/01/2012 15:00:00 4,150.00 4,320.00 4,150.00 4,310.00 4,310.00 96,568,200
11/01/2012 15:00:00 4,150.00 4,180.00 3,950.00 4,160.00 4,160.00 170,156,900
12/01/2013 15:00:00 4,240.00 4,280.00 4,120.00 4,130.00 4,130.00 171,484,000
13/01/2013 15:00:00 4,330.00 4,340.00 4,210.00 4,210.00 4,210.00 218,968,900
14/01/2013 15:00:00 4,270.00 4,300.00 4,270.00 4,280.00 4,280.00 207,410,700
15/01/2020 15:00:00 4,360.00 4,360.00 4,310.00 4,330.00 4,330.00 141,727,100
19/01/2020 15:00:00 4,340.00 4,350.00 4,300.00 4,320.00 4,320.00 130,044,800
with annual data like this (data2)
data2 = {'eps': ['100','231', '200', '167']}
df = pd.DataFrame(data2, index = [ '2017', '2018', '2019', '2020'])
with the contents of the (data2)
Year EPS
2017 100
2018 231
2019 200
2020 167
with the end result like this,
then nailed down the calculation of the division based on the eps year which is the same as the date on data1 with the calculation on P / EPS (P = Adj Close ** / EPS)
Date Open High Low Close* Adj Close** Volume Eps P / EPS
04/01/2017 4,330.00 4,390.00 4,300.00 4,390.00 4,390.01 186,370,900 100 43,9
05/01/2017 4,260.00 4,290.00 4,210.00 4,280.00 4,280.01 128,905,400 100 42,8
06/01/2017 4,280.00 4,300.00 4,160.00 4,200.00 4,200.01 116,634,000 100 42,0
07/01/2018 4,300.00 4,300.00 4,240.00 4,270.00 4,270.01 97,239,100 231 18,5
08/01/2018 4,150.00 4,320.00 4,150.00 4,310.00 4,310.01 96,568,200 231 18,7
11/01/2019 4,150.00 4,180.00 3,950.00 4,160.00 4,160.01 170,156,900 200 20,8
12/01/2019 4,240.00 4,280.00 4,120.00 4,130.00 4,130.01 171,484,000 200 20,7
13/01/2019 4,330.00 4,340.00 4,210.00 4,210.00 4,210.01 218,968,900 200 21,1
14/01/2020 4,270.00 4,300.00 4,270.00 4,280.00 4,280.01 207,410,700 167 25,6
15/01/2020 4,360.00 4,360.00 4,310.00 4,330.00 4,330.01 141,727,100 167 25,9
19/01/2020 4,340.00 4,350.00 4,300.00 4,320.00 4,320.01 130,044,800 167 25,9
what code should I enter in python
I really appreciate your friends who help me in the my learning process, thank you
question from:https://stackoverflow.com/questions/65649111/calculating-enter-and-calculate-new-data-by-annual-year