iT邦幫忙

0

python dataframe

執行下面程式碼會出現 但找不出原因 想問有人跑出來也會出現一樣錯誤嗎
'DataFrame' object has no attribute 'to_frame'

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
import statsmodels
import statsmodels.api as sm
from datetime import datetime


tech_list =['4938.TW','2317.TW']
tickers=['4938.TW','2317.TW']
end= '2014-12-31'
start= '2014-01-01'
print(start)
print (end)

from pandas_datareader import data as pdr
import fix_yahoo_finance as yf
yf.pdr_override(tickers)
data=pdr.get_data_yahoo(tech_list,start,end) 
data.to_frame().head(10)

https://ithelp.ithome.com.tw/upload/images/20190718/20113885FUOHK2lMIW.jpg

![https://ithelp.ithome.com.tw/upload/images/20190719/20113885Ew8Tbo0Boj.jpg]

froce iT邦大師 1 級 ‧ 2019-07-19 07:47:30 檢舉
to_frame是Series的方法,不是Dataframe的方法。
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.to_frame.html

你想想,你資料類型都是Dataframe了,還要轉成Dataframe要幹嘛?
ginbow iT邦新手 5 級 ‧ 2019-07-19 08:04:55 檢舉
對...謝謝 我昨天有發現type 已經是Dataframe
所以我後來改成 data.head(10) 但發現格式與結果不同
要如何整理成那樣? 找不到合適資料整併的方式
有什麼建議嗎
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答