US Financial Health project

I’m trying to do task 15, but nothing printed out. Is something wrong with my function?

This code produces an error:

Traceback (most recent call last):
  File "script.py", line 51, in <module>
    print(crude_oil_returns.var())
AttributeError: 'NoneType' object has no attribute 'var'

How do I solve this?

import codecademylib3_seaborn

import pandas as pd

import numpy as np

gold_prices = pd.read_csv('gold_prices.csv')

print(gold_prices)

#3

crude_oil_prices = pd.read_csv('crude_oil_prices.csv')

#4

import pandas_datareader.data as web

#5

from datetime import datetime

start_date = datetime(1999, 1, 1)

end_date = datetime(2019, 1, 1)

#6

nasdaq_data = web.DataReader('NASDAQ100', 'fred', start_date, end_date)

print(nasdaq_data)

#7

sap_data = web.DataReader('SP500', 'fred', start_date, end_date)

print(sap_data)

#8

import pandas_datareader.wb as wb

#9

gdp_data = wb.download(indicator = 'NY.GDP.MKTP.CD', country = ['US'], start = start_date, end = end_date)

#10

export_data = wb.download(indicator = 'NE.EXP.GNFS.CN', country = ['US'], start = start_date, end = end_date)

#11

def log_return(prices):

  np.log(prices/prices.shift(1))

#13

gold_returns = log_return(gold_prices['Gold_Price'])

#14

crude_oil_returns = log_return(crude_oil_prices['Crude_Oil_Price'])

sap_returns = log_return(sap_data['SP500'])

export_returns = log_return(export_data['NE.EXP.GNFS.CN'])

nasdaq_returns = log_return(nasdaq_data['NASDAQ100'])

gdp_returns = log_return(gdp_data['NY.GDP.MKTP.CD'])

print('gold:', gold_returns.var())

print(crude_oil_returns.var())

print(sap_returns.var())

print(export_returns.var())

print(nasdaq_returns.var())

print(gdp_returns.var())

Your error suggests crude_oil_returns is in fact the None object. What do you assign to this name, check any functions or method returns carefully.