3

The command with nbconvert i.e: $ jupyter nbconvert --to script [YOUR_NOTEBOOK].ipynb converts ipython to .py file but my python file output is something like this:

# In[1]:

  import pandas as pd

# In[2]:
  data = pd.read_csv('train.csv')
  d2  = pd.read_csv('test.csv')

I don't want the In[1]or In[2] lines at all. Is there any solution for this

Abhilash
  • 63
  • 6

1 Answers1

0

I found the solution to this problem here. The save magic command documentation saves the input lines you want to a file; the -a option is for "append" mode so that the lines are added at the end of the file instead of overwriting the file.

Just type

%save -a myipythonsession.py 1-100

1-100 represent the line numbers that you want to save (you don't have to actually have 100 lines you can also have less in your session)
-a will ensure that if the file that you save to already exists will not be overwritten, the lines that you save will be appended instead.

matyas
  • 2,696
  • 23
  • 29