AttributeError: 'NoneType' object has no attribute 'head'
AttributeError: 'NoneType' object has no attribute 'head'
import pandas as pd
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
ts = TimeSeries(key=api_key, output_format = 'pandas')
ti = TechIndicators(key=api_key, output_format='pandas')
data1, meta_data1 = ts.get_intraday(symbol = 'GOOGL' ,interval = '5min', outputsize = 'full')
data2, meta_data2 = ti.get_bbands(symbol = 'GOOGL' , interval='5min', time_period=60)
data = pd.concat([data1, data2], axis=1, sort=False)
data = data.rename(columns={'1. open': 'Open', '2. high': 'High', '3. low': 'Low', '4. close': 'Close'}, inplace = True)
data.head()
在上面的代码中,我从 alpha vantage api 导入数据。但是出现了上面的错误。请帮助我!
当您使用 inplace=True
时,rename
函数就地执行操作,而不是 return 具有重命名列的数据框。相反,它 returns None
,然后被分配给 data
- 使其成为 NoneType 对象。由于 data
不再是 df,调用 head()
会导致您遇到错误。
import pandas as pd
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
ts = TimeSeries(key=api_key, output_format = 'pandas')
ti = TechIndicators(key=api_key, output_format='pandas')
data1, meta_data1 = ts.get_intraday(symbol = 'GOOGL' ,interval = '5min', outputsize = 'full')
data2, meta_data2 = ti.get_bbands(symbol = 'GOOGL' , interval='5min', time_period=60)
data = pd.concat([data1, data2], axis=1, sort=False)
data = data.rename(columns={'1. open': 'Open', '2. high': 'High', '3. low': 'Low', '4. close': 'Close'}, inplace = True)
data.head()
在上面的代码中,我从 alpha vantage api 导入数据。但是出现了上面的错误。请帮助我!
当您使用 inplace=True
时,rename
函数就地执行操作,而不是 return 具有重命名列的数据框。相反,它 returns None
,然后被分配给 data
- 使其成为 NoneType 对象。由于 data
不再是 df,调用 head()
会导致您遇到错误。