Python Forum
Series object error message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Series object error message
#1
Hello,

I am trying to create data frame of Share prices based on data provided by vendor. I am getting an error message "'Series' object has no attribute 'close'" Can you please help me with this issue ?

import pandas as pd
from pandas import DataFrame
import quandl
import datetime as dt
quandl.ApiConfig.api_key =  
stock_list = pd.read_csv(r"F:\Abhay_New\Abhay\Python\Project\SHARADAR_SF1.csv")
end_date = dt.date.today()
diff_year = dt.timedelta(days=365)
start_date = end_date - diff_year
path = (r"F:\Tradepoint\MyMkt")
 
for i in range(len(stock_list)):
    data = quandl.get_table('SHARADAR/SEP', date={'gte':start_date, 'lte':end_date}, ticker=stock_list.iloc[i])
    if len(data)>1:
        dict = {'Date':data['date'],'OPEN':data['open'],'HIGH':data['high'],'LOW':data['low'],'CLOSE':data['close'],'VOLUME':data['volume']}
        final_data = pd.DataFrame(dict,columns = ['Date','OPEN','HIGH','LOW','CLOSE','VOLUME'])
        final_data.to_csv(path + '\\' + stock_list.iloc[i] + '.csv', index = False, header = False)
        print(final_data).head()

Error:
AttributeError: 'Series' object has no attribute 'close'
Reply
#2
Unfortunately, I do not have a Quandl account and cannot be bothered to set one up. Could you perhaps output the data variable or a sample of rows so that we can see its structure.

As per the error message, it seems like the returned object is a Series, not a DataFrame as seems to be implied from your code.

One word of caution on an unrelated topic, your assignment of a dictionary to a variable named dict will 'overwrite' the dict object. I would suggest using a different variable name.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get error message in a GAN neural network tutorial jdude50 0 1,648 Oct-22-2020, 11:11 PM
Last Post: jdude50
  TypeError: 'Series' object cannot be interpreted as an integer evelynow 2 17,599 Sep-11-2019, 02:43 PM
Last Post: timmahoney
  Error Message - Akainu 2 3,250 May-24-2019, 09:09 PM
Last Post: Akainu
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 18,756 May-22-2019, 02:31 PM
Last Post: twinpiques
  panda, excel - script pauses and doesn't continue running, no error message william 1 2,653 Nov-24-2018, 01:24 AM
Last Post: ichabod801
  Simple Series Keyword Error Kris 4 4,285 Jan-22-2017, 08:16 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020