sort_values() got an unexpected keyword argument 'by'
时间: 2023-10-01 15:09:27 浏览: 517
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.
阅读全文