1
代碼是用python 3.4編寫的,但我想在python 3.7上運行它。我正在使用Jupyter筆記本運行。我可以在Jupyter中創建一個環境並運行較早版本的熊貓中的代碼(例如0.16)嗎?排序:'DataFrame'對象沒有'排序'屬性
--> 210 tmpvals[n] = find_non_overlapping_sample(
211 df.sort_index(key, ascending=phase).head(600).index, prd = no_overlap_prd)
212
~\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
3079 if name in self._info_axis:
3080 return self[name]
-> 3081 return object.__getattribute__(self, name)
3082
3083 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'sort' `
即使我改變sort
到sort_index
或sort_values
。錯誤仍然存在。
這是函數(原始代碼)。
def gen_keydates(df, key, seasonalData=False, no_overlap_prd = 365, chatty=True):
tmpvals={}
if seasonalData: # For DJF data use modified function
for n, phase in enumerate([False, True]): # Maximum, Minimum Phase
tmpvals[n] = findNonOverlappingSeasonSample(
df.sort(key, ascending=phase).head(600).index, key=key)
else:
for n, phase in enumerate([False, True]): # Maximum, Minimum Phase
tmpvals[n] = find_non_overlapping_sample(
df.sort(key, ascending=phase).head(600).index, prd = no_overlap_prd)
compPhase ={}
compPhase['max'] = tmpvals[0][0:11].order()
compPhase['min'] = tmpvals[1][0:11].order()
if chatty:
print("Average for max/min sample of {0}: {1:2.3f} and {2:2.3f}".format(
key,np.mean(df[key][compPhase['max']]),
np.mean(df[key][compPhase['min']])))
return compPhase`
這是什麼熊貓版本? – EdChum
可能是最新版本,我在Jupyter上運行它。是否有可能將大熊貓降級到Jupyter的舊版本? –
'sort'已被棄用,您應該使用'sort_values',但您需要發佈代碼和環境的完整說明,即所有庫版本 – EdChum