JustTryItOut27
JustTryItOut27

Reputation: 55

I am looking for a simple way to extract python code from a notebook on kaggle?

I am new to Kaggle and using notebooks. I can see that I can fork notebooks on Kaggle, however, whenever I try to get the code by clicking on the Code tab, it provides the necessary python commands for analysis (which I want) along with a lot of code to produce the formatted text that shows up in the Notebook(which I don't want).

I was wondering if there was an easy way to just extract the python code needed for analysis, without all of the code meant to format the Notebook output. Could anyone help me with this? I suspect it must be simple, but I searched around for a while and couldn't seem to find what I was looking for. Thanks for your time.

Upvotes: 4

Views: 1339

Answers (1)

meW
meW

Reputation: 3967

Follow these steps:

  1. Visit the kernel you wish to retrieve the code of.
  2. Fork the kernel which will take you to an editor mode.
  3. From the editor mode, download the Ipython notebook.
  4. Run following command to convert the notebook into a python script and enjoy the code. !jupyter nbconvert --to script config_template.ipynb

For clear information on point 4, have a look on this webpage https://stackoverflow.com/a/19779226/10734525

Upvotes: 3

Related Questions