1

I learnt data manipulation and analysis through Stata and I used the log command to record all the commands written and the output generated. Doing so I could reproduce my findings, check previous results and share it with others in pdf or txt. What to use with Python? Is there a difference if I use a Python Jupyter Notebook or Spyder?

5
  • How are you executing python code currently? Do you have python installed locally? Are you running the python REPL interpreter? Commented Nov 29, 2018 at 6:05
  • Yes, it is installed locally with anaconda, I use Spyder or Jupyter, I m not sure about the REPL, is that for replication? Commented Nov 29, 2018 at 6:07
  • en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop Commented Nov 29, 2018 at 6:08
  • yes, then, I write a script in spyder or Jupyter and then I run it. How do I record the output of the script? E.g. Spyder has a different window for the output - so If I had to share my script with someone he can only see the script, not the output (a table or a regression analysis) Commented Nov 29, 2018 at 6:14
  • If you want him to reproduce the findings, then he will have to run the script to generate the table. If you want him to see the table quickly, you can take a screenshot of the result yourself and send it as an image. Commented Nov 29, 2018 at 6:19

2 Answers 2

0

The way to do what you want is by using the %logstart command, as described here:

Log IPython output?

Sign up to request clarification or add additional context in comments.

1 Comment

this is very useful, thanks! a friend of mine also recommended me to use the logging function. I will look into it and provide more details after testing it. That's the advice I got: angelaambroz.com/blog/posts/2018/Mar/13/writing_better_python
0

Stop using the python interpreter and start storing your commands in a text file before running them. This way you will be able to share, reuse, and revise your python code.

By executing the following command:

python code.txt

Python will read all of the lines in your file sequentially.

This is the main way python programs are executed, as a convention, python code files end with .py , so if you see a file with a .py extension, you can try executing it yourself using this method!

4 Comments

Thanks, but this method won't help with storing outpust, say a graph created with matplotlib, right? Or the output of a scikit-learn regression command. I just don't think it is efficient to take a screenshoot to all the outputs - it would be nice to have scripts and outputs automatically generated in the same document (txt or pdfor whatever..)
So this question answers how you can reproduce the results, maybe you could ask another question asking how to share the results. You should include details about the output you are generating. Depending on the type of output you generate, there will be a way to store the raw data in some serialized form. For example, if you have a plot, you can share a text file with all of the coordinates, or each coordinate for a given frequency of a formula. This heavily depends on your code, though, so please include these details in your next question.
Sorry for the confusion, I understand now there is no a single solution. Thanks for the help.
There is a single solution, but it depends on details you haven't posted yet. You haven't posted the details because you didn't deem them necessary for answering your original question "How to REPRODUCE your findings with Python" You now need to post these details because your question has changed. Your question has changed because your original question was solved. I encourage you to create another question if this is the case. This way we can ensure that we leave generic answers for generic questions for people in a similar position without making a really big super specific question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.