刚才的问题出现了这个报错sort_values() got an unexpected keyword argument 'by'
时间: 2023-07-30 19:07:08 浏览: 1509
这个报错通常是由于使用了过期的`sort_values()`方法参数导致的。在较新的Pandas版本中,`sort_values()`方法已更新为使用`by`参数的`sort_values()`方法不再支持。要解决此问题,请使用以下代码:
```python
df = df.sort_values('column_name')
```
这将按照指定的列名对数据框进行排序。
相关问题
sort_values() got an unexpected keyword argument 'by'
The error message "sort_values() got an unexpected keyword argument 'by'" indicates that you are using the "by" argument with the "sort_values" function, which is not a valid argument for this function.
In pandas, the "sort_values" function is used to sort a DataFrame or Series by a specified column or columns. To sort a DataFrame by a specific column, you can simply pass the column name to the "sort_values" function as follows:
```
df.sort_values('column_name')
```
If you want to sort by multiple columns, you can pass a list of column names to the "sort_values" function:
```
df.sort_values(['column_name_1', 'column_name_2'])
```
Note that the "by" argument is not required for the "sort_values" function, as it is used for other sorting functions in pandas.
Series.sort_values() got an unexpected keyword argument 'by'
这个错误通常是因为您使用了错误的参数。在Pandas中,sort_values()方法不支持“by”参数。正确的语法是sort_values(by=None, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None)。您可以尝试删除“by”参数并使用其他参数来排序您的Series。
阅读全文