Series.sort_values() got an unexpected keyword argument 'by'
时间: 2023-05-18 22:07:24 浏览: 180
这个错误通常是因为您使用了错误的参数。在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。
相关问题
TypeError: Series.sort_values() got an unexpected keyword argument 'by'
这个错误通常是因为 `sort_values()` 方法中使用了不支持的参数。在 Pandas 1.0.0 版本之前,`sort_values()` 方法的排序键参数为 `by`,但在 1.0.0 版本中被更改为 `key`。因此,如果你的 Pandas 版本是 1.0.0 及以上,使用 `by` 参数会导致 TypeError。
解决方法是将 `by` 参数改为 `key`。例如:
```python
df.sort_values(key='column_name')
```
如果你的 Pandas 版本低于 1.0.0,请升级到最新版本以获得更好的支持和体验。
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.