【发布时间】:2017-11-05 20:26:59
【问题描述】:
我也在做一个简单的交易,需要一些帮助来将数据框连接在一起。直到现在我的方法都行不通。
我的代码如下:
连接到 quantle API
quandl.ApiConfig.api_key = 'xxxxxxxxxxxxxxx'
股票代码
ticker = ['FSE/ZO1_X',"FSE/WAC_X"]
用 pandas 的引号创建一个面板对象 -> 创建一个 pandas DataFrame
df = quandl.get(ticker, start_date='2017-01-01', end_date='2017-11-03')
从面板数据集中切出每只股票的收盘价
close1 = df['FSE/ZO1_X - Close']
close2 = df['FSE/WAC_X - Close']
将两个数据框连接在一起 - 此步骤不起作用
close = pd.concat(close1,close2)
close1 和 close 2 的类型是 pandas.core.series.Series。
如何将 close1 和 close2 放在一起,以便索引是日期,并且我有另外两列股票 1 (close1) 和股票 2 (close2) 的收盘价 - 类似于普通的 Excel 表。
【问题讨论】:
-
声音很大。
-
需要
[]喜欢close = pd.concat([close1,close2])吗? -
解释
.concat()的工作原理。
标签: python pandas dataframe concatenation stock