I have a dataframe with one column that contains a list of countries. I basically want to transform it to a new column that says "Inside US" if the row contains either United States or Puerto Rico, otherwise "Outside US". How can I do this in pandas?
Expected input:
countries
United States, Japan
China
Brazil, South Africa
Puerto Rico, Spain
United States, Vietnam
Madagascar
Expected output:
countries
Inside US
Outside US
Outside US
Inside US
Inside US
Outside US
My attempt: The following code gives me a true or false series which I'm struggling to use..Also not sure if this is the best way to start.
df['countries'].str.contains('United States|Puerto Rico')