Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在面板中保存不同形状的数据帧?I';我试图制作一个面板,以数据帧的形式存储所有股票的数据集_Python 3.x_Pandas_Dataframe_Panel - Fatal编程技术网

Python 3.x 如何在面板中保存不同形状的数据帧?I';我试图制作一个面板,以数据帧的形式存储所有股票的数据集

Python 3.x 如何在面板中保存不同形状的数据帧?I';我试图制作一个面板,以数据帧的形式存储所有股票的数据集,python-3.x,pandas,dataframe,panel,Python 3.x,Pandas,Dataframe,Panel,使用雅虎,您可以一次调用多只股票。Yahoo reader会自动将它们加载到多索引数据框中。在查询开始时不存在的股票将作为NaN填写。您将获得[打开,高,低,关闭,调整关闭,音量] 我已经准备了一份股票的清单,以供演示 import pandas as pd import fix_yahoo_finance as fyf from pandas_datareader import data as web # this is a work around for yahoo deprecation

使用雅虎,您可以一次调用多只股票。Yahoo reader会自动将它们加载到多索引数据框中。在查询开始时不存在的股票将作为NaN填写。您将获得[打开,高,低,关闭,调整关闭,音量]

我已经准备了一份股票的清单,以供演示

import pandas as pd
import fix_yahoo_finance as fyf
from pandas_datareader import data as web

# this is a work around for yahoo deprecation
fyf.pdr_override()

# to load multiple stocks into one dataframe
stocks = ['FB', 'AMZN', 'NFLX', 'GOOG']
data = web.get_data_yahoo(stocks, start = '2017-01-01', end='2019-01-01')

# to see results...
data.head(3)
获取所有股票的开盘和收盘数据

data.loc[:,['Open', 'Close']]
使用pd.indexlice进行灵活的筛选

idx = pd.IndexSlice
data.loc[:,idx[['Open', 'Close'],['GOOG', 'FB']]]
要使用Quandl,您可以使用以下内容:

import pandas as pd
from pandas_datareader import data as web
import quandl
quandl.ApiConfig.api_key = 'YOUR_QUANDL_KEY'

stocks = ['FB', 'AMZN', 'NFLX', 'GOOG']

stocks = web.DataReader(name = stocks, data_source = 'quandl', start = '2018-01-01', end = '2018-12-31', 
                access_key = 'YOUR_QUANDL_KEY')
stocks = stocks.sort_index(ascending = True)

你只是将数据帧存储在一个位置以便以后检索吗?是的!Orelse我必须在我编写的每个函数中使用一个循环来获得所需的数据。根据互联网,我意识到使用面板是在函数中过滤掉它的最好方法,而不是在每个函数中反复调用股票数据。我很高兴,你介意投票回答吗?感谢您这么做,声誉问题不会公开显示!很抱歉