Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing Data to CSV
#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

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'
Reply
#2
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)
Reply
#3
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.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 170 6 hours ago
Last Post: deanhystad
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,006 Dec-06-2022, 11:09 AM
Last Post: mg24
  Create a function for writing to SQL data to csv mg24 4 1,150 Oct-01-2022, 04:30 AM
Last Post: mg24
  Need Help writing data into Excel format ajitnayak87 8 2,503 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  Fastest Way of Writing/Reading Data JamesA 1 2,186 Jul-27-2021, 03:52 PM
Last Post: Larz60+
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,279 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  writing data to a csv-file apollo 1 2,364 Jul-03-2020, 02:28 PM
Last Post: DeaD_EyE
  python openpyxl writing data Bikram 2 2,451 Oct-17-2019, 03:33 PM
Last Post: Bikram
  Who converts data when writing to a database with an encoding different from utf8? AlekseyPython 1 2,360 Mar-04-2019, 08:26 AM
Last Post: DeaD_EyE
  Help with Code (Writing Data File) caroline_d_124 3 2,849 Jan-06-2019, 09:17 PM
Last Post: caroline_d_124

Forum Jump:

User Panel Messages

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