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

1 Answer 1

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.

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

Comments

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.