筛选出data中label列的值不等于-1的所有数
时间: 2023-11-28 17:49:18 浏览: 21
假设data是一个DataFrame,其中包含label列,可以使用以下代码筛选出label列的值不等于-1的所有行:
```python
filtered_data = data[data['label'] != -1]
```
这将返回一个新的DataFrame,其中只包含label列的值不等于-1的行。
相关问题
element-plus 表格 tableData 按照某一列 表头筛选 代码
您可以使用 element-plus 表格组件的 `filter-method` 属性来实现按照某一列表头筛选的功能。`filter-method` 属性接受一个函数作为参数,该函数会在表格组件渲染时自动调用。您可以在这个函数中自定义筛选方法,根据需要返回符合条件的数据。
以下是一个示例代码,演示如何按照某一列表头筛选表格数据:
```html
<template>
<div>
<el-input v-model="filterKey" placeholder="请输入关键字"></el-input>
<el-table :data="tableData" :column-filter-method="filterHandler">
<el-table-column prop="name" label="姓名" :filters="nameFilters"></el-table-column>
<el-table-column prop="age" label="年龄" :filters="ageFilters"></el-table-column>
<el-table-column prop="gender" label="性别" :filters="genderFilters"></el-table-column>
</el-table>
</div>
</template>
<script>
export default {
data() {
return {
filterKey: '',
tableData: [
{ name: '张三', age: 18, gender: '男' },
{ name: '李四', age: 20, gender: '女' },
{ name: '王五', age: 22, gender: '男' }
],
nameFilters: [
{ text: '张三', value: '张三' },
{ text: '李四', value: '李四' },
{ text: '王五', value: '王五' }
],
ageFilters: [
{ text: '18', value: 18 },
{ text: '20', value: 20 },
{ text: '22', value: 22 }
],
genderFilters: [
{ text: '男', value: '男' },
{ text: '女', value: '女' }
]
}
},
methods: {
filterHandler(value, row, column) {
const property = column.property;
return row[property].indexOf(value) > -1;
}
}
}
</script>
```
在上面的代码中,我们使用了 `column-filter-method` 属性来指定筛选方法。在 `el-table-column` 组件中,我们使用了 `filters` 属性来指定筛选项。在 `filterHandler` 方法中,我们根据当前列的属性名来获取当前列的值,然后使用 JavaScript 的字符串方法 `indexOf()` 来进行模糊匹配,返回符合条件的数据。
您可以根据实际需要修改筛选方法和筛选项。需要注意的是,当表格数据数量较大时,使用筛选功能可能会影响性能。
el-table 带筛选 设置筛选框尺寸 筛选框 不能输入
el-table 是 Element UI 提供的一个表格组件,可以用于展示数据。它提供了丰富的功能和配置选项,包括筛选功能。
要设置 el-table 的筛选框尺寸并且禁止输入,可以通过配置 el-table-column 的 filter-method 和 filter-input-attributes 属性来实现。
首先,设置 el-table-column 的 filter-method 属性为一个自定义的方法,该方法用于筛选数据。在该方法中,可以通过返回 true 或 false 来决定是否显示该行数据。
其次,设置 el-table-column 的 filter-input-attributes 属性为一个对象,该对象用于设置筛选框的属性。可以通过设置 disabled 属性为 true 来禁止输入。
下面是一个示例代码:
```html
<template>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="name" label="姓名" :filter-method="filterMethod" :filter-input-attributes="filterInputAttributes"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ name: '张三', age: 18 },
{ name: '李四', age: 20 },
{ name: '王五', age: 22 }
],
filterInputAttributes: {
disabled: true
}
};
},
methods: {
filterMethod(value, row) {
// 自定义筛选方法
return row.name.indexOf(value) !== -1;
}
}
};
</script>
```
在上面的示例中,el-table-column 的 prop 属性指定了要显示的数据字段,label 属性指定了列的标题。filter-method 属性绑定了一个自定义的筛选方法 filterMethod,该方法根据输入的值和行数据进行筛选。filter-input-attributes 属性设置了筛选框的属性,其中 disabled 属性设置为 true,禁止输入。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)