0

I am trying to use the yfinance API to gather stock data in Python and don't know how to manipulate column data. For instance, using this code:

import yfinance as yf

ko = yf.download("KO", start = '2021-11-26', end = '2021-12-15')

print(ko)
print(type(ko))

I get this output:

                 Open       High        Low      Close  Adj Close    Volume
Date                                                                       
2021-12-08  55.119999  55.349998  54.360001  55.000000  55.000000  18026300
2021-12-09  54.750000  55.130001  54.590000  54.860001  54.860001  13846400
2021-12-10  55.250000  56.320000  55.070000  56.279999  56.279999  23151000
2021-12-13  56.980000  57.930000  56.959999  57.759998  57.759998  31362800
2021-12-14  57.400002  58.169998  57.400002  57.799999  57.799999  24806600
<class 'pandas.core.frame.DataFrame'>

I want to just grab a single column and use that data. How do I take each 'Close' value and add them up into the sum?

Also, the class type is pandas DataFrame, if that means anything.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • What do you mean by "How do I take each 'Close' value and add them up into the sum?"? Do you mean like [Get total of Pandas column](https://stackoverflow.com/q/41286569/15497888) -> `ko['Close'].sum()`? – Henry Ecker Dec 16 '21 at 00:40
  • 1
    Henry, that's exactly what I needed! XD Thank you. – Hung Chigis Dec 16 '21 at 00:45

0 Answers0