I am cleaning a database and I need to clean also the location field. The data is taken from a forum, so the entrance are self compiled. For this reason I have a lot of weird and different stuff going on here and I don't know how to get rid of them, especially of redundancies.
To give you an idea my list is really big: 4 millions entries, but for my purposes it can be also reduced a bit. This is the link to a short version with 10000 entries (https://ufile.io/y4akb) and this the one with all the 4 million entries (https://ufile.io/9ecxl). I already tried the function Interpreter or to work around it with GeoPosition, but apparently is no use, or at least I takes too much computational time and memory.
Can someone suggest a good approach to this? I would accept also answers which involves other softwares like R or/and SQLite. I hope someone from the communities can actually help me solving this. I am not uploading my codes because it is not really helpful and might be misleading because I am still a beginner in Mathematica.
My optimal result would be a list with only the name of the countries. Maybe also as strings, so it doesn't suck up so much memory.
Thank you in advance for your help!
--- EDIT TO CLARIFY DESIRED OUTPUT ---
Here it is an example of the Dataset I am working on:
And the final result I would like to achieve is the following:
POSSIBLE APPROACH
Using all the tips is the comments a possible approach I naively thought is to create a list with the locations and edit them with a nested If cycle like the following, and once I have the correct list, just to plug it in back as a column. In case someone has a better code, or a smarter way to deal with ALL the possible cases would be super happy and interested in his/her approach. Meanwhile, here it is the code:
Location = Table[
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Poland"],
"Poland",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Pakistan"],
"Pakistan",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Brazil"],
"Brazil",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Netherlands"],
"Netherlands",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Iran"],
"Iran",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Ireland"],
"Ireland",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Japan"],
"Japan",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Spain"],
"Spain",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Turkey"],
"Turkey",
If[
StringContainsQ[LongTableAnswerLocation[[i]], "Sweden"],
"Sweden",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"Bangladesh"], "Bangladesh",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"Australia"], "Australia",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"France"], "France",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"China"], "China",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"Russia"], "Russia",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"Canada"], "Canada",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"Germany"], "Germany",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"United Kingdom" | "UK"], "United Kingdom",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"India"], "India",
If[
StringContainsQ[LongTableAnswerLocation[[i]],
"AL" | "AK" | "AZ" | "AR" | "CA" | "CO" | "CT" |
"DE" | "FL" | "GA" | "HI" | "ID" | "IL" | "IN" |
"IA" | "KS" | "KY" | "LA" | "ME" | "MD" | "MA" |
"MI" | "MN" | "MS" | "MO" | "MT" | "NE" | "NV" |
"NH" | "NJ" | "NM" | "NY" | "NC" | "ND" | "OH" |
"OK" | "OR" | "PA" | "RI" | "SC" | "SD" | "TN" |
"TX" | "UT" | "VT" | "VA" | "WA" | "WV" | "WI" |
"WY" | "AS" | "DC" | "FM" | "GU" | "MH" | "MP" |
"PW" | "PR" | "VI" | "New York" | "USA"],
"United States"
, LongTableAnswerLocation[[i]]]
]]]]]]]]]]]]]]]]]]],
{i, Length@LongTableAnswerLocation}];
#["Name"] & /@ EntityList["Country"]
) takes like a half hour and times out half the time ) $\endgroup$