Python DataFrame 对象没有属性“sort_values”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34499728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:05:02  来源:igfitidea点击:

DataFrame object has no attribute 'sort_values'

pythonpandasdataframe

提问by Klausos Klausos

dataset = pd.read_csv("dataset.csv").fillna(" ")[:100]
dataset['Id']=0
dataset['i']=0
dataset['j']=0
#...
entries=dataset[dataset['Id']==0]
print type(entries)  # Prints <class 'pandas.core.frame.DataFrame'>
entries=entries.sort_values(['i','j','ColumnA','ColumnB'])

What might be the possible reason of the following error message at the last line?:

最后一行出现以下错误消息的可能原因是什么?:

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

采纳答案by Romain

Hello sort_valuesis new in version 0.17.0, so check your version of pandas. In the previous versions you should use sort.

Hellosort_values0.17.0 版本中的新版本,因此请检查您的 pandas 版本。在以前的版本中,您应该使用sort.

entries=entries.sort(['i','j','ColumnA','ColumnB'])

回答by Gagan

Check pandas version, In new versions uses sort_values in place of sort.

检查 pandas 版本,在新版本中使用 sort_values 代替 sort。