Search code examples
pythonpandasdata-analysisalgorithmic-tradingalpha-vantage

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()

In the above code, I am importing data from alpha vantage api. But the above error ocurred. Please help me!


Solution

  • When you use inplace=True, the rename function does the operation in-place, and does not return a dataframe with renamed columns. Instead, it returns None, which then gets assigned to data - making it a NoneType object. Since data is no longer a df, calling head() on it leads to the error you're getting.