How do I compare two columns in a Pandas DataFrame and output values from other columns based on the match?
So I have a pandas dataframe.
A: 3, 4, 1, 2, 1,
B 1, 2, 3, 4
C Red, Blue, Yellow, Green
D Yes, No, Maybe, True
what I want to be able to do is sequentially check column A against column B, if there is a match then output C and D relative to B.
For example the data frame above would be converted into A Yellow, Green, Red, Blue, Red B Maybe, True, Yes, No, Yes
I am rather new to python and pandas so I might be missing something simple here but I cannot think of solutions for this problem and am unsure where to start to find an answer. Any help would be appreciated
-Smoggs
Many various ideas. I know I should be using iloc to target the value in the cell, but I am unsure how to output the result next to it. I'm really at a loss here
source https://stackoverflow.com/questions/76360074/how-do-i-compare-two-columns-in-a-pandas-dataframe-and-output-values-from-other
Comments
Post a Comment