2016-07-03 50 views
0

我下面哈佛CS109-功課-1的 https://github.com/cs109/contentAttributeError的:「據幀」對象有沒有屬性「日期」

上iPythonNotebook

解碼,並有此錯誤(我沒有改變解決方案代碼)運行這行代碼後「的錯誤= all_error_data()」:

errors = all_error_data() 


/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:67: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....) 
/anaconda/lib/python2.7/site-packages/ipykernel/__main__.py:46: FutureWarning: .resample() is now a deferred operation 
use .resample(...).mean() instead of .resample(...) 
--------------------------------------------------------------------------- 



AttributeError       Traceback (most recent call last) 
<ipython-input-18-aea6d425eefd> in <module>() 
----> 1 errors = all_error_data() 

<ipython-input-17-2a9c686164e8> in all_error_data() 
    17 #your code here 
    18 def all_error_data(): 
---> 19  data = [error_data(race_page) for race_page in find_governor_races(page)] 
    20  return pd.concat(data, ignore_index=True) 

<ipython-input-14-5c576ec1e316> in error_data(url) 
    48  #compute forecast length in days 
    49  #(assuming that last forecast happens on the day of the election, for simplicity) 
---> 50  forecast_length = (df.date.max() - df.date).values 
    51  forecast_length = forecast_length/np.timedelta64(1, 'D') # convert to number of days 
    52 

//anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name) 
    2667    if name in self._info_axis: 
    2668     return self[name] 
-> 2669    return object.__getattribute__(self, name) 
    2670 
    2671  def __setattr__(self, name, value): 

AttributeError: 'DataFrame' object has no attribute 'date' 

感謝很多關於分享的建議!

回答

1

我遇到了同樣的問題並做了一些研究。對pandas.resample進行了一些更改,該更改現在更改了DataFrame並刪除了非數字數據。

的pd.resample後沒有「數據」列,以便爲固定代碼只是改變了第50行,以解決索引列,而不是數據合作:

forecast_length = (df.index.max() - df.index).values 
相關問題