Python Forum
Writing Data to CSV - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Writing Data to CSV (/thread-20380.html)



Writing Data to CSV - abhaydd - Aug-08-2019

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

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


AttributeError: 'Series' object has no attribute 'close'



RE: Writing Data to CSV - Larz60+ - Aug-08-2019

can you add
import sys
then:
        print(f"data: {data}")
        sys.exit(0)
after line 15 and show results(the exit so it doesn't dump entire file)


RE: Writing Data to CSV - DeaD_EyE - Aug-09-2019

api.key
Please remove this API Key now.

It's now public and everyone can use it, if it's still valid.

The problem is, that your data has not they key 'closed'.
dict = {'Date':data['date'],'OPEN':data['open'],'HIGH':data['high'],'LOW':data['low'],'CLOSE':data['close'],'VOLUME':data['volume']}

I am not familiar with pandas, but I guess there is a technique to avoid problems with missing data.
In science they have to fight with this issue everyday. Crappy data, which is sometimes not valid or it's completely missing.