DataFrame.sort_values() missing 1 required positional argument: 'by'
时间: 2023-09-21 20:07:51 浏览: 440
The error message "DataFrame.sort_values() missing 1 required positional argument: 'by'" typically occurs when you try to call the `sort_values()` method of a pandas DataFrame without specifying the "by" parameter, which is required to indicate the column(s) to sort by.
To fix this error, you need to specify the "by" parameter and provide the name(s) of the column(s) you want to sort by. For example, if you have a DataFrame called "df" and you want to sort it by the "col1" column, you can do:
```python
df.sort_values(by='col1')
```
You can also sort by multiple columns by passing a list of column names to the "by" parameter. For example:
```python
df.sort_values(by=['col1', 'col2'])
```
This will first sort the DataFrame by the "col1" column, and then sort by the "col2" column for any ties in "col1".
阅读全文