rasbt / machine-learning-book

Code Repository for Machine Learning with PyTorch and Scikit-Learn
https://sebastianraschka.com/books/#machine-learning-with-pytorch-and-scikit-learn
MIT License
3.63k stars 1.31k forks source link

AttributeError: 'DataFrame' object has no attribute 'append' for Pandas >=2 #182

Closed decorouz closed 4 months ago

decorouz commented 4 months ago

If you are like me, using the latest version of some of the dependencies to follow along, there is a gotcha you should lookout for: With Pandas 2.0+ release in April of 2023, Pandas deprecated the . append() method

https://github.com/rasbt/machine-learning-book/blob/af519a1aae331481ae3a22210d51fd40c37fdae0/ch08/ch08.py#L158

This line of code will throw an AttributeError. The work around is:

...
new_row = pd.DataFrame({'review': [txt], 'sentiment': [labels[l]]})
df = pd.concat([df, new_row], ignore_index=True)
rasbt commented 4 months ago

Thanks for the note, and good catch. I had a fix for that in the notebook but totally missed applying it to the Python script as well. Should be fixed now. Thanks for the note!