self.df['X'] = self.df['x'].apply(lambda x: my_map.get(x))
如何删除my_map.get(x)
返回None
的行。
我正在寻找一种解决方案,我不必再次遍历列以删除行。
由于
答案 0 :(得分:4)
我认为您需要dropna
,因为可以在第一步中删除foreach (CustomTextCell textCell in parentSection)
{
System.Diagnostics.Debug.WriteLine($"{textCell.Text} - {textCell.IsChecked}");
}
,通过分配给新列创建None
s:
NaN
或者:
self.df['X'] = self.df['x'].apply(lambda x: my_map.get(x))
self.df = self.df.dropna('X')
答案 1 :(得分:2)
public ActionResult Edit(int id)
{
// didnt make sense
// getIssue.item = getIssue.items[id - 1];
Issue getIssue = IssueReposiroty.GetIssueById(id) // exaqmple as no idea hgow retrieved
return View(getIssue);
}
[HttpPost]
public ActionResult Edit(Issue issue)
{
If(ModelState.IsValid)
{
// process saving of updated item
// can pass id or pass model to save retrieving again
return RedirectToAction("IssueItem", issue);
}
else
{
ModelState.AddModelError(string.Empty, "Please make sure you have filled in all required fields.");
}
return View(issue);
}
public ActionResult IssueItem(Issue issue)
{
return View(issue);
}
或loc
获取可调用参数并返回可调用计算结果为pd.Series.compress
的子集
<强> True
强>
compress
<强> self.df['x'].compress(lambda x: my_map.get(x) is not None)
强>
loc
答案 2 :(得分:1)
您可以按以下方式找到索引
idxs = self.df.index[self.df['X'].isnull()] # find all indices with None in df.X
完整代码:
self.df['X'] = self.df['x'].apply(lambda x: my_map.get(x))
idxs = self.df.index[self.df['X'].isnull()] # find all indices with None in df.X
self.df = self.df.drop(idxs)
答案 3 :(得分:0)
如果您将mymap
转换为词典:
mymerge = pd.DataFrame.from_dict(mymap, orient = 'index')
然后使用左连接,仅加入所需的列:
mymerge.merge(df, left_index = True, right_on = 'x')
在一行中:
pd.DataFrame.from_dict(mymap, orient = 'index').merge(df, left_index = True, right_on = 'x')