我必须删除数据帧行中的值(如果它们包含某个字符串)。 问题是该行很长并且包含文本。
循环不起作用,将索引放在列表中,然后在索引上使用.drop也不起作用。
function rowappend() // this one is appending row
{
var markup = $('<tr><td><input type="text" class="form-control commantd"name="itemNametd" id="itemNametd">' +
'</td><td id="itemCodetd" class="commantd"></td>' +
'<td><input type="text" class="form-control commantd"name="unitQtytd" id="unitQtytd"></td>' +
'<td id="purRatetd" class="commantd"></td>' +
'<td><input type="text" class="form-control commantd"name="discPercentagetd" id="discPercentagetd"></td>' +
'<td id="discAmttd" class="commantd"></td>' +
'<td id="gstPercentagetd" class="commantd"></td>' +
'<td id="gstAmttd" class="commantd"></td>' +
'<td id="totalAmttd" class="commantd"></td></tr>');
$("table tbody").append(markup);
$("#itemNametd", markup).focus();
}
rowappend()
var data = [ //data to populate Item Name search input field
{
"ItemName": "Butter"
},
{
"ItemName": "Rice"
},
{
"ItemName": "Milk"
},
{
"ItemName": "Ice Cream"
},
{
"ItemName": "Curd"
}
]
var data1 = [{ // this data will be dynamic but for now to test i am using this single data
"ItemName": "Butter",
"ItemCode": 400564,
"PurRate": 8,
"DiscAmt": 6,
"gstPercentage": 35,
"gstAmt": 5
}]
var totalAmount = "";
var unitQuantity = "";
$(function() {
let itemName = data.map(value => { //using autocomplete to for searching input field
return value.ItemName;
});
$("#itemNametd").autocomplete({
source: itemName
});
});
$("#itemNametd").focusout(function() { //when user focus out from Item Name doing this
data1.map(value => {
$("#itemCodetd").text(value.ItemCode);
$("#purRatetd").text(value.PurRate);
$("#discAmttd").text(value.DiscAmt);
$("#gstPercentahgetd").text(value.gstPercentage);
$("#gstAmttd").text(value.gstAmt);
});
});
$("#unitQtytd").focusout(function() { //when user focus out Unit Qty doing some calculation
unitQuantity = $("#unitQtytd").val();
purchaseRate = $("#purRatetd").text();
totalAmount = (parseInt(unitQuantity) * parseInt(purchaseRate));
$("#totalAmttd").text(totalAmount);
});
$('body').on('focusout', '#discPercentagetd', function() {
rowappend()
});
谢谢
答案 0 :(得分:1)
假设您的数据框名为df
。然后使用:
df_filtered = df[~df['column1'].str.contains('total')]
说明:
df['column1'].str.contains('total')
将为您提供数据帧列长度的数组,无论True
包含df['column1']
是'total'
。使用~
交换此数组的True
和False
值。最后,在df_filtered = df[...]
中,您仅采用了不包含'total'
的行。
答案 1 :(得分:0)
如果我正确理解,下面有一个小例子,其中dataFrame被称为df
,并且我想删除要搜索和删除的mixfruit
。
>>> df
name num
0 apple 5
1 banana 3
2 mixfruit 5
3 carret 6
一种方法可以与其他str.contains
一起使用,如下所示。.
>>> df[~df.name.str.contains("mix")]
name num
0 apple 5
1 banana 3
3 carret 6
您也可以使用isin
,这将删除所有包含字符串
>>> df[~df['name'].isin(['mixfruit'])]
name num
0 apple 5
1 banana 3
3 carret 6
但是,您可以实现以下目标...
>>> df[df['name'] != 'mixfruit']
name num
0 apple 5
1 banana 3
3 carret 6