如何选择包含数据集中特定值的每一行?我想要你使用的选择标准是它是否在其中一个单元格中包含特定值。 我疯狂地探索文献中心和这个论坛。我也生气了,因为我完全知道如果我们想要使用数据集,我们应该用mathematica做一个常见的工作,但不幸的是我没有线索。
例如,这是我为我的问题创建的一个小型数据库
{{"user_id;language;country;destination;search_for;criteria"},
{"1; it; italy; greece; hotel; 3*, parking, pool"},
{"1; it; italy; greece; appartment; parking, pool"},
{"2; en; usa; usa; hotel; 5*, golf"},
{"3; fr; france; spain; hotel; 4*, pool, shuttle"},
{"3; fr; france; spain; hotel; 3*, shuttle"},
{"3; fr; france; france; hotel; 3*, 4*, shuttle, pool"},
{"3; fr; france; france; hotel; 4*, shuttle, pool, parking"},
{"4; en; usa; bahamas; hotel; 4*"},
{"4; en; usa; mexico; hotel; 4*"},
{"5; en; uk; spain; hotel; shuttle"},
{"5; en; uk; spain; hotel; shuttle, pool"},
{"6; de; germany; italy; appartment; pool, parking"},
{"6; de; germany; italy; hotel; pool, parking"},
{"6; de; germany; greece; appartment; pool"},
{"7; fr; switzerland; france; hotel; 4*},
{"8; en; canada; usa; hotel; 4*, SPA"},
{"9; de; switzerland; italy; hotel; 4*, SPA"},
{"9; de; switzerland; italy; hotel; 4*, pool, fitness"},
{"10; it; italy; italy; appartment; parking, petfriendly"}}
请不要关心我做的糟糕的显示。
我的观点是,例如: 我必须在“条件”列中选择包含“池”一词的每一行 这只是数据库的一个例子。我想要工作的那个已经在“.mx”文件中了,我用以下方式导入:
SetDirectory@SystemDialogInput["Directory"];
FileNames[]
mydata = Import["main.mx"]
并显示为proper table(如excel)
答案 0 :(得分:3)
调用您的列表lst
并使用
Pick[lst, StringContainsQ[Flatten[lst], "pool"]]
答案 1 :(得分:2)
data = {
{"user_id;language;country;destination;search_for;criteria"},
{"1; it; italy; greece; hotel; 3*, parking, pool"},
{"1; it; italy; greece; appartment; parking, pool"},
{"2; en; usa; usa; hotel; 5*, golf"},
{"3; fr; france; spain; hotel; 4*, pool, shuttle"},
{"3; fr; france; spain; hotel; 3*, shuttle"},
{"3; fr; france; france; hotel; 3*, 4*, shuttle, pool"},
{"3; fr; france; france; hotel; 4*, shuttle, pool, parking"},
{"4; en; usa; bahamas; hotel; 4*"},
{"4; en; usa; mexico; hotel; 4*"},
{"5; en; uk; spain; hotel; shuttle"},
{"5; en; uk; spain; hotel; shuttle, pool"},
{"6; de; germany; italy; appartment; pool, parking"},
{"6; de; germany; italy; hotel; pool, parking"},
{"6; de; germany; greece; appartment; pool"},
{"7; fr; switzerland; france; hotel; 4*"},
{"8; en; canada; usa; hotel; 4*, SPA"},
{"9; de; switzerland; italy; hotel; 4*, SPA"},
{"9; de; switzerland; italy; hotel; 4*, pool, fitness"},
{"10; it; italy; italy; appartment; parking, petfriendly"}};
cols = First[StringSplit[First[data], ";"]];
d2 = Flatten[StringSplit[#, "; "] & /@ Rest[data], 1];
sel = Select[d2, StringMatchQ[Last@#, "*pool*"] &];
Grid[Prepend[sel, cols], Alignment -> Left, Frame -> All, Spacings -> {1, 1}]