Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to understand what Python elements (?) are doing

Hi,
I'm a newbie to Python. I have programmed in R and am struggling a little when trying to follow along with some of the code written and shared on these forums.

I am working through the (Machine Learning on Quantopian code and am stuck because I cannot understand what these functions are doing...

results_wo_returns = results.copy()  
returns = results_wo_returns.pop('Returns')  
Y = returns.unstack().values  
X = results_wo_returns.to_panel()  
X = X.swapaxes(2, 0).swapaxes(0, 1).values # (factors, time, stocks) -> (time, stocks, factors)  

For copy, I was able to lookup via np.copy? though I am not sure if this is correct given its being run on results which is a pandas dataframe. For the other elements, I cannot find these definitions.

Another thing I don't understand is where Returns is suddenly dropped in results_wo_returns

I appreciate this is a pretty basic question, but I'm struggling to progress without understanding this, and am not even sure what to google.

Much appreciated,
J

1 response

I figured this out by googling python and the function. I thought this would be in the documentation using the ? as advised. I don't appear to be able to delete my own question so leaving it here in case some one else has the same question some time later.