I have a dataframe containing customers charges and the charges on their contract. I want to compare the respective charges for each customer and flag what doesn't match for each one. Here is what the df looks like:
| Resident | Tcode | MoveIn | 1xdisc | 1xdisc_doc | conpark | rent | rent_doc |
|---|---|---|---|---|---|---|---|
| Marcus | t0011009 | 3/16/2021 | 0.0 | -500.0 | 0.0 | 0 | 1632 |
| Joshua | t0011124 | 3/20/2021 | 0.0 | 0.0 | 0.0 | 1642 | 1642 |
| Yvonne | t0010940 | 3/17/2021 | -500.0 | -500.0 | 0.0 | 1655 | 1655 |
| Mirabeau | t0011005 | 3/19/2021 | -500.0 | -500.0 | 0.0 | 1931 | 1990 |
| Keyonna | t0011084 | 3/18/2021 | 0.0 | 0.0 | 0.0 | 1600 | 1600 |
| Ariel | t0010954 | 3/22/2021 | -300.0 | 0.0 | 0.0 | 1300 | 1320 |
I want to add a column containing all the problems for each row as a string. here is the output I would like, with column 'Problem' containing all the problems for each row:
| Resident | Tcode | MoveIn | 1xdisc | 1xdisc_doc | conpark | rent | rent_doc | Problem |
|---|---|---|---|---|---|---|---|---|
| Marcus | t0011009 | 3/16/2021 | 0.0 | -500.0 | 0.0 | 0 | 1632 | rent doesn't match. 1xdisc doesn't match |
| Joshua | t0011124 | 3/20/2021 | 0.0 | 0.0 | 0.0 | 1642 | 1642 | |
| Yvonne | t0010940 | 3/17/2021 | -500.0 | -500.0 | 0.0 | 1655 | 1655 | |
| Mirabeau | t0011005 | 3/19/2021 | -500.0 | -500.0 | 0.0 | 1931 | 1990 | rent doesn't match. |
| Keyonna | t0011084 | 3/18/2021 | 0.0 | 0.0 | 0.0 | 1600 | 1600 | |
| Ariel | t0010954 | 3/22/2021 | -300.0 | 0.0 | 0.0 | 1300 | 1320 | rent doesn't match. 1xdisc doesn't match |
So far I am trying
nonmatch["Problem"] = np.where(nonmatch['rent'] != nonmatch['rent_doc'], "rent doesn't match", nonmatch["Problem"] + "")
nonmatch["Problem"] = np.where(nonmatch['1xdisc']!=nonmatch['1xdisc_doc']), " 1xdisc doesn't match.", "")
print(nonmatch[['Resident','Problem']])
but then any errors that were already in the cell get overwritten. How do I add a string to the contents of the cell if the condition is met?
I also have a hunch that there must be a cleaner way to do this apply lambda, but I'm not sure how. I have about ten conditions I want to check for, but this is a minimal example.