简体   繁体   中英

Concatenate two pandas data frames together (in python)

I am working on a simple trading also and need some help with concatenating to data frames together. Until my now my approach does't work.

My code is the following:

Connect to quantle API

 quandl.ApiConfig.api_key = 'xxxxxxxxxxxxxxx'

Ticker symbols

ticker = ['FSE/ZO1_X',"FSE/WAC_X"]

Create a panel object with quotes from panda -> create a pandas DataFrame

 df = quandl.get(ticker, start_date='2017-01-01', end_date='2017-11-03')

Slicing the close prices for each stock out of the panel data set

close1 = df['FSE/ZO1_X - Close']
close2 = df['FSE/WAC_X - Close']

Concatenate the two data frames together - THIS STEP DOESN'T WORK

 close = pd.concat(close1,close2)

The type of close1 and close 2 is pandas.core.series.Series.

How can I put close1 and close2 together, so that the index is the date and I have two additional columns with the close prices of stock 1 (close1) and stock 2 (close2) - similar like an ordinary excel sheet.

close = pd.concat([close1, close2], axis=1)

should do it.

Full example:

import pandas as pd 
import numpy as np

s = pd.Series([1,2,3,4,5])
t = pd.Series([11,12,13,14,15])
s = pd.concat([s,t], axis=1)
print(s)

Output:

   0   1
0  1  11
1  2  12
2  3  13
3  4  14
4  5  15

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM