The answer provided by @Niccola Tartaglia is good advice. Generally, do computations in pipeline when possible.
However, it's not always a clear cut answer. For simple arithmetic and boolean logic between factors, pipeline uses numexpr, which is very fast, faster than pandas or numpy manipulation of dataframe columns. However, if one is applying a very selective screen to your pipeline, there may be much less data to operate on after the pipeline is run. In this case, even though the computations may be slower, the total time may be faster (by operating on less data).
Logic inside custom factors is less clear cut. If one executes identical numpy calculations inside a custom factor vs after the pipeline is returned, the speed will probably be comparable. Again, it depends upon how much data is being operated on so pay attention to masks and screens.
Pipeline is typically more memory efficient too. If one is outputting a number of columns just to combine them later in pandas, you'll save memory by doing the work in pipeline. Additionally, it's easy to unintentionally end up with copies of the output dataframe when doing calculations after a pipeline is returned.
So, generally, if you can do something easily in pipeline, it's probably faster and/or more memory efficient to do it there.
Now, the second half to the original question was "how do I go about this? Simple if statements never seem to work" . True, in defining calculations for pipeline, 'if statements' are not defined. Often one doesn't need them however. Maybe take a look at this post for some ideas on how to implement Piotroski F score (https://www.quantopian.com/posts/piotroskis-f-score-algorithm )
Good luck.
Disclaimer
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.