我是python编码的新手,请帮我 我有一个Excel文件Gold ETF.xlsx
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
%matplotlib inline
gold = pd.read_excel('Gold ETF.xlsx',index_col=0, parse_dates=True).dropna()
gold.head()
它显示
Reliance ETF Gold BeES
Date Close
2016-01-01 00:00:00 2280.2
2016-01-04 00:00:00 2304.7
2016-01-05 00:00:00 2319.65
2016-01-06 00:00:00 2333.1
但是,当我接下来写的时候
gold['Returns'] = np.log(gold['Close'] / gold['Close'].shift(1))
print(gold['Returns'])
gold['Returns'].plot()
它给
KeyError Traceback (most recent call last)
C:\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
3077 try:
-> 3078 return self._engine.get_loc(key)
3079 except KeyError:
KeyError: 'Close'
我已经尝试过通过将其转换为csv并使用pd.read_csv重新加载,但是它显示了相同的键错误“关闭”,在反复尝试后我无法弄清楚 我已经显示数据已正确装载,数据帧的名称为金色,其中包含“关闭”列,但仍然显示错误