I’m guessing you’re using pandas? It is helpful to include that kind of
information. The docs for the .where method seem to be here:
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.where.html
You’ve written you test incorrectly. You wrote:
.where(df2['Medication.Medication'] == "Atenolol", "Carvedilol", other=0)
Because of the comma, that supplies these 3 parameters:
df2['Medication.Medication'] == "Atenolol"
"Carvedilol"
other=0
which means that (a) you are only testing against “Atenolol” and (b)
you’re specifying “Carvedilol” as the “other” parameter. And also
specifying 0 as the “other” parameter.
In reflection, I am surprised that this is even accepted by Python.
Please always provide code directly copied from your running
programme.
You need to ensure the entire test is one parameter. For example:
.where(df2['Medication.Medication'] in ("Atenolol", "Carvedilol"), other=0)
which supplies these 2 parameters:
df2['Medication.Medication'] in ("Atenolol", "Carvedilol")
other=0
Also notice that the test checks for the medication being in a tuple of
possible values. A common beginner mistake in Python is to try to write
such a test like this:
df2['Medication.Medication'] == "Atenolol" or "Carvedilol"
which does not mean what is wanted. instead, that is read by Python as:
df2['Medication.Medication'] == "Atenolol"
or
"Carvedilol"
Cheers,
Cameron Simpson cs@cskk.id.au