Search code examples
wolfram-mathematica

How do you extract rows that contains specific string?


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"

enter image description here

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.


Solution

  • 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}}