英文:
How do you extract rows that contains specific string?
问题
我试图从导入的数据集中提取包含特定字符串的所有行,该数据集有5列。如果一行包含特定字符串,它将在第2列中。
以下是您尝试的代码,但是它没有给出任何结果:
monkeypox[All, "Germany"]
要提取包含特定字符串的所有行,您可以使用Select
函数。这是一个可能的方法:
result = Select[monkeypox, #[[2]] == "Germany" &]
这将为您提供包含特定字符串"Germany"的所有行。
无需翻译代码部分,只返回翻译好的部分。
英文:
I'm trying to extract all rows, that contains a specific string from an imported dataset, that has 5 columns. If a row had the specific string it would be in the 2 column.
monkeypox = Import["/Users/unknowen/Desktop/ProMat/Eksamen Jan
2023/monkeypox.csv", "Dataset"]
The Data --->
monkeypox = {{"DateRep", "CountryExp", "CountryCode", "Source",
"ConfCases"}, {"2022-04-22", "Austria", "AT", "TESSy",
0}, {"2022-04-22", "Belgium", "BE", "TESSy", 0}, {"2022-04-22",
"Bulgaria", "BG", "TESSy", 0}, {"2022-04-22", "Croatia", "HR",
"TESSy", 0}, {"2022-04-22", "Cyprus", "CY", "TESSy",
0}, {"2022-04-22", "Czechia", "CZ", "TESSy", 0}, {"2022-04-22",
"Denmark", "DK", "TESSy", 0}, {"2022-04-22", "Estonia", "EE",
"TESSy", 0}, {"2022-04-22", "Finland", "FI", "TESSy",
0}, {"2022-04-22", "France", "FR", "TESSy", 0}, {"2022-04-22",
"Germany", "DE", "TESSy", 0}, {"2022-04-22", "Greece", "EL",
"TESSy", 0}, {"2022-04-22", "Hungary", "HU", "TESSy",
0}, {"2022-04-22", "Iceland", "IS", "TESSy", 0}, {"2022-04-22",
"Ireland", "IE", "TESSy", 0}, {"2022-04-22", "Italy", "IT", "TESSy",
0}, {"2022-04-22", "Latvia", "LV", "TESSy", 0}, {"2022-04-22",
"Lithuania", "LT", "TESSy", 0}, {"2022-04-22", "Luxembourg", "LU",
"TESSy", 0}, {"2022-04-22", "Malta", "MT", "TESSy",
0}, {"2022-04-22", "Netherlands", "NL", "TESSy", 0}, {"2022-04-22",
"Norway", "NO", "TESSy", 0}, {"2022-04-22", "Poland", "PL", "TESSy",
0}, {"2022-04-22", "Portugal", "PT", "TESSy", 1}, {"2022-04-22",
"Romania", "RO", "TESSy", 0}, {"2022-04-22", "Slovakia", "SK",
"TESSy", 0}, {"2022-04-22", "Slovenia", "SI", "TESSy",
0}, {"2022-04-22", "Spain", "ES", "TESSy", 0}, {"2022-04-22",
"Sweden", "SE", "TESSy", 0}, {"2022-04-29", "Austria", "AT",
"TESSy", 0}, {"2022-04-29", "Belgium", "BE", "TESSy",
0}, {"2022-04-29", "Bulgaria", "BG", "TESSy", 0}, {"2022-04-29",
"Croatia", "HR", "TESSy", 0}, {"2022-04-29", "Cyprus", "CY",
"TESSy", 0}, {"2022-04-29", "Czechia", "CZ", "TESSy",
0}, {"2022-04-29", "Denmark", "DK", "TESSy", 0}, {"2022-04-29",
"Estonia", "EE", "TESSy", 0}, {"2022-04-29", "Finland", "FI",
"TESSy", 0}, {"2022-04-29", "France", "FR", "TESSy",
0}, {"2022-04-29", "Germany", "DE", "TESSy", 0}, {"2022-04-29",
"Greece", "EL", "TESSy", 0} }
THE SPECIFIC STRING IS "Germany"
This is what I have tried to do but I have no idea how to do it with string values.
monkeypox[All, "Germany"]
This code gives me nothing btw.
答案1
得分: 0
感谢您的数据。这显示演示中没有隐藏任何内容。
尝试
Cases[monkeypox, {_, "Germany", _, _, _}]
或者
Select[monkeypox, #[[2]] == "Germany" &]
这两者中的任何一个都会返回
{{2022-04-22, Germany, DE, TESSy, 0}, {2022-04-29, Germany, DE, TESSy, 0}}
英文:
Thank you for your data. That showed nothing was hiding in the presentation.
Try
Cases[monkeypox,{_,"Germany",_,_,_}]
or
Select[monkeypox,#[[2]]=="Germany"&]
Either of those return
{{2022-04-22,Germany,DE,TESSy,0},{2022-04-29,Germany,DE,TESSy,0}}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论