DataFrame.filter(items=None, like=None, regex=None, axis=None)
时间: 2023-10-04 15:03:29 浏览: 37
`DataFrame.filter()` is a method in pandas library which is used to subset a DataFrame based on column labels or row indices. It takes the following parameters:
- `items`: list-like object of column labels to subset
- `like`: string to match in column labels to subset
- `regex`: regular expression to match in column labels to subset
- `axis`: axis to filter on (0 for rows, 1 for columns)
You can use any one of the above parameters (items, like, regex) to filter the DataFrame. If you pass the `items` parameter, it will subset the DataFrame based on the specified column labels. If you pass the `like` parameter, it will subset the DataFrame based on column labels that contain the specified string. If you pass the `regex` parameter, it will subset the DataFrame based on column labels that match the specified regular expression.
For example, to subset a DataFrame `df` based on column labels that contain the string "price", you can use the following code:
```
df.filter(like='price', axis=1)
```
This will return a DataFrame with only the columns that contain the string "price" in their labels.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)