How to resolve ??AttributeError: 'NoneType' object has no attribute 'head'

6.9k views Asked by At

I am working with stock data from Google, Apple, and Amazon. All the stock data was downloaded from yahoo finance in CSV format. I have a file named GOOG.csv containing the Google stock data, a file named AAPL.csv containing the Apple stock data, and a file named AMZN.csv containing the Amazon stock data. I am getting an error when I am trying to check the output of the data frame.

google_stock = google_stock.rename(columns={'Adj Close':'google_stock'},inplace=True)

# Change the Adj Close column label to Apple
apple_stock = apple_stock.rename(columns={'Adj Close':'apple_stock'},inplace=True)

# Change the Adj Close column label to Amazon
amazon_stock = amazon_stock.rename(columns={'Adj Close':'amazon_stock'},inplace=True)

google_stock.head()```


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-b562791246eb> in <module>()
      1 # We display the google_stock DataFrame
----> 2 google_stock.head()

AttributeError: 'NoneType' object has no attribute 'head'
1

There are 1 answers

0
U13-Forward On BEST ANSWER

inplace=True makes it update without assigning, so either use:

google_stock.rename(columns={'Adj Close':'google_stock'},inplace=True)

# Change the Adj Close column label to Apple
apple_stock.rename(columns={'Adj Close':'apple_stock'},inplace=True)

# Change the Adj Close column label to Amazon
amazon_stock.rename(columns={'Adj Close':'amazon_stock'},inplace=True)

google_stock.head()

Or use normal assignment without inplace=True:

google_stock = google_stock.rename(columns={'Adj Close':'google_stock'})

# Change the Adj Close column label to Apple
apple_stock = apple_stock.rename(columns={'Adj Close':'apple_stock'})

# Change the Adj Close column label to Amazon
amazon_stock = amazon_stock.rename(columns={'Adj Close':'amazon_stock'})

google_stock.head()