我想把数据收集到朱莉娅。我有DataArrays.DataArray{String,1}名为"brokenDf“,它包含我想从dataframe和dataframe "df”中删除的串行id。
我得到的最接近的是“发现”
df[findin(df[:serial],brokenDf),:];
但是,我不知道在这之后如何翻转它,或者我们是否在朱莉娅中有NOT IN命令。因此,它的工作方式类似于findNOTin()。
如有任何建议,将不胜感激。
发布于 2017-04-28 18:35:19
一种解决方案是使用map()并创建一个Bool数组来对数据的行进行子集:
using DataFrames
df = DataFrame(serial = 1:6, B = ["M", "F", "F", "M", "N", "N"]);
broken = [1,2,5];
df[DataArray{Bool}(map(x -> !(x in broken), df[:serial])),:]产出如下:
3×2 DataFrames.DataFrame
│ Row │ serial │ B │
├─────┼────────┼─────┤
│ 1 │ 3 │ "F" │
│ 2 │ 4 │ "M" │
│ 3 │ 6 │ "N" │注意,!否定您的布尔条件,所以!true == false。
发布于 2017-04-26 10:43:59
下面应该做你想做的事:
using DataFrames
df = DataFrame(A = 1:6, B = ["M", "F", "F", "M", "N", "N"]);
# Rows where B .== "M"
f1 = find(df[:, 2] .== "M");
# Rows where B is not "M"
f2 = find(df[:, 2] .!= "M");
# Rows where B is not "M" and is not "F"
f3 = reduce(&, (df[:, 2] .!= "F", df[:, 2] .!= "M"));后者可以自动编写函数:
# Define function
function find_is_not(x, conditions)
temp = sum(x .!= conditions, 2);
res = find(temp .== length(conditions));
return res;
end
# Rows where B is not "M" and is not "F" (with find_is_not)
f4 = find_is_not(df[:, 2], ["M" "F"]);发布于 2019-04-21 14:26:53
使用列表理解的解决方案是:
df = df[[!(i in brokenDf) for i in df.serial], :]这将给出过滤后的DataFrame,其中df.serial不在brokenDf中。
https://stackoverflow.com/questions/43631215
复制相似问题