Answer a question

I am trying to concat along 2 columns in pandas. The code :

import pandas as pd
import numpy as np
from statsmodels import api as sm
import pandas_datareader.data as web
import datetime

start = datetime.datetime(2015,2,12)
end = datetime.datetime.today()
df = web.get_data_yahoo(['F', '^GSPC'], start, end)

df1 = df.concat(columns=[F['Close'], gspc['Close']], axis=1)

But i am getting the following error:

AttributeError: 'DataFrame' object has no attribute 'concat'

Answers

You need to use pd.concat([df1, df2]), because df.concat() doesn't exist.

I'll make you an example:

import pandas as pd

df1 = pd.DataFrame(zip(list('bcdfg'), list('aeiou')), columns=['consonants', 'vowels'])
df2 = pd.DataFrame(range(5), columns=['numbers'])
  consonants vowels
0          b      a
1          c      e
2          d      i
3          f      o
4          g      u
   numbers
0        0
1        1
2        2
3        3
4        4
pd.concat([df1, df2], axis=1)
  consonants vowels  numbers
0          b      a        0
1          c      e        1
2          d      i        2
3          f      o        3
4          g      u        4
Logo

学AI,认准AI Studio!GPU算力,限时免费领,邀请好友解锁更多惊喜福利 >>>

更多推荐