2

I would like to copy and paste data from a Jupyter notebook. As per the following example which includes the In and Out elements.

When trying to copy this data I am currently unable to select the In and Out elements as these are not contained in the cell data.

In [23]:
df.index.slice_indexer(start_remove, end_remove)

Out[23]:
slice(36, 85, None)

This image shows the In and Out elements as well as the cells. I want to copy and paste all of this.

enter image description here

nipy
  • 5,138
  • 5
  • 31
  • 72
  • Try saving as a python script - is this what you want? – Phlya Jan 07 '17 at 11:47
  • Thanks for looking @Phlya. No, I just want to copy and pate as per the image I just added. So when doing a copy and paste it would show the `In [149]:` , `In [150]:` and `Out [150]:` values as well as the cell data. I'm pretty sure it can be done as I did it accidentally before but can't work out how... – nipy Jan 07 '17 at 11:54
  • 1
    I see. Saving as a script doesn't preserve the output, true. – Phlya Jan 07 '17 at 11:55
  • @EdChum, is this something you did here? http://stackoverflow.com/questions/41513324/python-pandas-drop-rows-of-a-timeserie-based-on-time-range/41514608?noredirect=1#comment70235633_41514608 as you have the `In` and `Out` data in your post. cheers – nipy Jan 07 '17 at 11:56
  • Why do you want to do this? – Seanny123 Jan 07 '17 at 12:12
  • It helps when showing others how your code is written and what values are returned. Please see the link in the comment above for examples. @Seanny123 – nipy Jan 07 '17 at 12:15
  • @ade1e Want to know an ugly hack for it? – Mohammad Yusuf Jan 07 '17 at 12:38
  • please show me @MYGz – nipy Jan 07 '17 at 12:41
  • If you start ipython in terminal, you can do it easily. – Mohammad Yusuf Jan 07 '17 at 13:18
  • Maybe this is how others are getting the output. – nipy Jan 08 '17 at 18:57
  • 1
    I think this is to do with some loss of functionality that occurred between my version `3.1.0-cbccb68` and `4.0`, this stopped me from upgrading any further – EdChum Jan 12 '17 at 20:27
  • @EdChum Check the better hack. – Mohammad Yusuf Jan 13 '17 at 05:35

1 Answers1

4

Less ugly hack:

You can do this in console of Inspection Tool:

$('div.prompt').removeClass('prompt')

And you don't have to refresh the page. You can carry on your coding with the prompt class removed from all the div elements. And you can select what you want at all times. But if you create new cells, you will have to run that again.


Ugly hack:

Steps:

  1. Right click on In [number] in your browser and click on Inspect Element

You will see something like this:

`<div class="prompt input_prompt">In&nbsp;[18]:</div>`
  1. Double click on class and remove the prompt class from the div element. After removing it, it will look like this:

    <div class="input_prompt">In&nbsp;[18]:</div>

  2. Press Enter and close the inspection tool.

  3. Now click and select from left of I in In [] and drag your mouse inside the code block.

  4. Voila! You got what you wanted.

  5. You can replace prompt back or just refresh the page.

Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78