参考)
PandasのDataFrameへの要素へのアクセス
import yfinance as yf
DJIA = yf.Ticker("DJIA")
data=DJIA.history(
start="2020-06-11",
end='2020-06-18'
)
print(data)
Open High Low Close Volume Dividends Stock Splits
Date
2020-06-10 27251.89 27355.22 26938.05 26989.99 6570840000 0 0
2020-06-11 26282.51 26294.08 25082.72 25128.17 7018890000 0 0
2020-06-12 25659.42 25965.55 25078.41 25605.54 5832250000 0 0
2020-06-15 25270.39 25891.58 24843.18 25763.16 5740660000 0 0
2020-06-16 26326.68 26611.03 25811.70 26289.98 5829240000 0 0
2020-06-17 26330.52 26400.07 26068.41 26119.61 4549390000 0 0
print(data.keys())
Index(['Open', 'High', 'Low', 'Close', 'Volume', 'Dividends', 'Stock Splits'], dtype='object')
print(data.index.values) //pandas
['2020-06-18T00:00:00.000000000' '2020-06-19T00:00:00.000000000']
print(data.columns.values) //pandas
['Open' 'High' 'Low' 'Close' 'Volume']
print(data['Close'])
Date
2020-06-10 26989.99
2020-06-11 25128.17
2020-06-12 25605.54
2020-06-15 25763.16
2020-06-16 26289.98
2020-06-17 26119.61
Name: Close, dtype: float64
print(data['Close'].keys())
DatetimeIndex(['2020-06-10', '2020-06-11', '2020-06-12', '2020-06-15',
'2020-06-16', '2020-06-17'],
dtype='datetime64[ns]', name='Date', freq=None)
print(data['Close'].values())
TypeError: 'numpy.ndarray' object is not callable
print(data['Close'].items())
<zip object at 0x000000000743ED88>
for price in data['Close']:
print(price)
25128.17
25605.54
25763.16
26289.98
26119.61
0 件のコメント:
コメントを投稿