COURSE NAME: Getting Market Data, SECTION: 9, Unit 1. Unit type: notebook

For the following code: 


Extract article details and append to the DataFrame

    for article in articles['articles']:

        date = pd.to_datetime(article['publishedAt'])

        title = article['title']

        articles = article['description']

        link = article['url']



        article_info = article_info.append({'Date': date, 'Title': title,

                                            'Articles': articles, 'Link': link}, ignore_index=True)



Getting two errors: 

1. KeyError: 'description'

2.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/zl/spmtrdq13t55wjzv3ggg6m600000gn/T/ipykernel_41032/692999486.py in ?()
      4     title = article['title']
      5     #articles = article['description']
      6     link = article['url']
      7 
----> 8     article_info = article_info.append({'Date': date, 'Title': title,
      9                                         'Articles': articles, 'Link': link}, ignore_index=True)

~/anaconda3/lib/python3.11/site-packages/pandas/core/generic.py in ?(self, name)
   5985             and name not in self._accessors
   5986             and self._info_axis._can_hold_identifiers_and_holds_name(name)
   5987         ):
   5988             return self[name]
-> 5989         return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'append'
Please could you help me fix this? the code is copied exactly as per the course notebook.

Hey Anna,



The code in the course notebook seems to be running fine. 



The error you encountered, "AttributeError: 'DataFrame' object has no attribute 'append'," may be due to a version mismatch. Please ensure that you are using pandas version 1.4.4. If not, you can upgrade it using the following pip command:

pip install --upgrade pandas==1.4.4

Could you also share the code that you have used? This would help us understand why you are getting the description KeyError.

Thanks
Rushda

Hi Rushda,



Thank you for your answer. The code used is in the beggining of my question, which is exactly the same as the code in the module.



Thanks!

Hey Anna,



We are unable to replicate the keyerror as the code in the course is running without errors. You can download this notebook from the downloadable unit at the end of the course. Then, you can run this notebook on your local system after entering your API key.



Thanks

Rushda