1

In Python, if I have a data frame in which I want to alter the contents in a particular column from one specific value to another, I so far use the following method using numpy:

df["Country"] = np.where(df["Country"] == "UK", "United Kingdom", df["Country"])
df["Country"] = np.where(df["Country"] == "USA", "United States", df["Country"])

I have about 100 of these types of changes, which looks ungainly in code. Can an example be provided in how to alter the above code in a way that would look more elegant when having numerous extra changes?

user1309044
  • 317
  • 3
  • 13

0 Answers0