[英]Pandas concat dataframes with different columns: AttributeError: 'NoneType' object has no attribute 'is_extension'
[英]Concat 2 columns in pandas - AttributeError: 'DataFrame' object has no attribute 'concat'
我試圖在熊貓中連接 2 列。 編碼 :
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)
但我收到以下錯誤:
AttributeError: 'DataFrame' object has no attribute 'concat'
您需要使用pd.concat([df1, df2])
,因為df.concat()
不存在。
我給你舉個例子:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.