Code Sample, a copy-pastable example if possible
# Your code here
import pandas as pd
df = pd.DataFrame({'A'=[1,2,3],'B'=[3,2,1]})
Here, I need something like the following,
C should be, True = if the row value of A is less than the value of B. Else False.
Without a for loop.
df.C.tolist() should be [True, False, False]
Problem description
[this should explain why the current behaviour is a problem and why the expected output is a better solution.]
Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!
Note: Many problems can be resolved by simply upgrading pandas
to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if master
addresses this issue, but that is not necessary.
For documentation-related issues, you can check the latest versions of the docs on master
here:
https://pandas-docs.github.io/pandas-docs-travis/
If the issue has not been resolved there, go ahead and file it in the issue tracker.
Expected Output
Output of pd.show_versions()
Comment From: chris-b1
Please use stackoverflow for usage questions: https://stackoverflow.com/questions/tagged/pandas
Here you want:
In [64]: df['A'] < df['B']
Out[64]:
0 True
1 False
2 False
dtype: bool
Comment From: Giftlin
@chris-b1 , Yes, but I need the results in a column. Also, for multiple if conditions for the same. A<B and B-1<A
Something like this. But the result must be in a new column of the same DataFrame