Storing multi index data frame in Matlab for data analysis and processing
9 ビュー (過去 30 日間)
古いコメントを表示
I run the following code wrapping yfinance a
% Define the stock tickers
tickers = {'AAPL', 'MSFT', 'GOOGL'}; % Apple, Microsoft, Google
% Set the start and end dates for the data
start_date = '2020-01-01';
end_date = '2021-01-01';
% Import the yfinance module
yfinance = py.importlib.import_module('yfinance');
% Download the data for all tickers at once
data = yfinance.download(py.list(tickers), start_date, end_date);
disp(data)
and my output looks like this:
Python DataFrame with properties:
T: [1×1 py.pandas.core.frame.DataFrame]
at: [1×1 py.pandas.core.indexing._AtIndexer]
attrs: [1×1 py.dict]
axes: [1×2 py.list]
columns: [1×1 py.pandas.core.indexes.multi.MultiIndex]
dtypes: [1×1 py.pandas.core.series.Series]
empty: 0
flags: [1×1 py.pandas.core.flags.Flags]
iat: [1×1 py.pandas.core.indexing._iAtIndexer]
iloc: [1×1 py.pandas.core.indexing._iLocIndexer]
index: [1×1 py.pandas.core.indexes.datetimes.DatetimeIndex]
loc: [1×1 py.pandas.core.indexing._LocIndexer]
ndim: [1×1 py.int]
shape: [1×2 py.tuple]
size: [1×1 py.int]
values: [1×1 py.numpy.ndarray]
Price Close ... Volume
Ticker AAPL GOOGL MSFT ... AAPL GOOGL MSFT
Date ...
2020-01-02 72.796005 68.186821 153.938202 ... 135480400 27278000 22622100
2020-01-03 72.088303 67.830101 152.021408 ... 146322800 23408000 21116200
2020-01-06 72.662704 69.638054 152.414352 ... 118387200 46768000 20813700
2020-01-07 72.320969 69.503548 151.024643 ... 108872000 34330000 21634100
2020-01-08 73.484344 69.998253 153.430283 ... 132079200 35314000 27746500
... ... ... ... ... ... ... ...
2020-12-24 129.047501 86.394814 215.745163 ... 54930100 9312000 10550600
2020-12-28 133.663040 88.377617 217.885666 ... 124486200 27650000 17933500
2020-12-29 131.883301 87.570557 217.101135 ... 121047300 19726000 17403200
2020-12-30 130.758759 86.498932 214.708817 ... 96452100 21026000 20272300
2020-12-31 129.751556 87.315475 215.425537 ... 99116600 21070000 20942100
[253 rows x 15 columns]
I wanted to save only Closing price of all tickers in Matlab, maintaining the Date as index for further processing. Can anyone help me? It will be appreciated.
0 件のコメント
回答 (1 件)
Jacob Mathew
2025 年 1 月 6 日
Hey Prashant,
Looking through the API Documentation of yfinance's download function, it doesn't seem possible to download a specific set of columns. You can double check at the documentation link below:
However, once you have the DataFrame entirely in MATLAB, you can convert it into a MATLAB compatible format like Table to help you extract the columns that you need. You can refer to the following example to help you out:
This example can also be launched running the following command from MATLAB's Command Line:
openExample('matlab/UsePythonPandasDataFramesInMATLABExample')
参考
カテゴリ
Help Center および File Exchange で Google についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!