Hi, i have got a travel dataset and I need to split the destination column into two columns, one column is city and another column is country name, for example, “Sydney, Australia” will be split into sydney in city column and australia in country column.
This is the original data:
Note that none of your questions are really about working with InMemoryDatasets (or DataFrames or similar), they are generally about how to work with simple vectors so it can often be edifying to reduce the MWE to just that.
You then need to think about how you deal with the fact that some country names are missing - one way would be to construct a tuple where the second element is just an empty string if the country is missing:
has two capture groups (enclosed in parens): the first capture group ([^,]+) matches one or more (+) non-comma characters. After this group, it optionally matches a comma (,?) and zero or more spaces (\s*) before getting to the next capture group (.*) which matches everything remaining.
When using this regex with match, you can access the matched capture groups by indexing (or collecting).