Writing a header in iPython Notebook causes the header to be invisible - python

In iPython Notebook running Python 2.x, when we write a markdown #header in a new cell and execute it, nothing appears
Every word I've tried seem to work for the header except header. How can we have a header with the word header?

I get the same issue. Here is a workaround.
<h1> header

I get the same problem in jupyter. Saving the notebook does not make the '#' markup symbol go away and leaves the text in a garish blue color, as you illustrate with the image you shared.
The only way I can get the header to assume its proper appearance is to close the notebook and reopen it. Then the text appears as it should.

Related

VS Code Jupyter Notebooks - How to stop result text wrapping?

When using Jupyter Notebooks within VS Code is it possible to stop the code cell result text from wrapping?
When querying wide dataframes (Eg 100 columns wide) the resulting text is unreadable due to the text wrapping and requires copying out to other text editors to be able to read the results.
Attached is a screenshot of a simple dataframe header that is wrapping over a couple of lines, once you're returning actual rows it's unusable.
Screenshot
This could be a limitation of Jupyter's UI. I recommend you to see your data in variable explorer and data viewer. By clicking theĀ VariablesĀ icon in the top side after running, you'll see a list of the current variables. For additional information of the variables, you can double-click on a row or use the Show variable in data viewer button to see a more detailed view.

Identation coverts to weird arrow while copying code from sublime to jupyter notebook

Copying this piece of code from sublime :
# Texts Texts Texts Texts Texts Texts
for i in range(10):
#Idented Texxt
print i
results in below, with the line tab in jupyter-notebook. Now if i want to add to the code and do further testing in jupyter, i need to copy this weird arrow instead of hitting tab (else, it shows indentation error). Is there some simple way to change? I can imagine I am missing something really simple and this might not be a problem at all. I tried looking but found no mention of this. I can change all the indentation to space in sublime and this might work while copying but I rather work with tabs, to make codes readable.
Second image with double tabs, how it looks like in notebook.
After copying the scripts to Jupyter cells from sublime:
Select all the lines with arrows
Press Tab - This will remove the arrows and add a tab at the beginning of each line
Press Shift + Tab - This will delete all the added tabs in the step above
It looks like the reason that this is happening to you is due to a mismatch in the world view of tools (i.e. Sublime and Jupyter in this case) with regards to tabs versus spaces, a perennial dispute indeed.
In particular in Sublime you have translate_tabs_to_spaces turned off because you want to work with physical tab characters. So pressing Tab in Sublime will insert physical tab characters which are visualized via the tab_size setting.
On the other hand, according to this issue, Jupyter does not support indentation via tabs when you press the Tab key. As such in Jupyter despite your best intentions, when you press Tab it's inserting spaces instead. It does however support physical tabs if they're pasted in, which is why it appears the way it does above and why you have to manually paste physical tabs to get the input that you need.
Of these two tools, Sublime allows you to choose whether you use physical tabs or space characters, but Jupyter does not and always wants spaces. The most expedient solution in that case would be to not use tabs in Sublime either and then everything would match up.
Presumably that's not an option for you, so the next best solution would be to bridge the gap by having Sublime provide the data to Jupyter in a way that it expects, which is possible with a simple plugin.
In Sublime, select Tools > Developer > New Plugin... and replace the stub with this code, then save in the default location that Sublime will prompt you with (your User package) with a recognizable name such as copy_with_spaces.py:
import sublime
import sublime_plugin
class CopyWithSpacesCommand(sublime_plugin.TextCommand):
"""
Copy the selected text to the clipboard, replacing all tab characters with
spaces based on the tab size in the current view.
"""
def run(self, edit):
self.view.run_command("copy")
tab_size = self.view.settings().get("tab_size", 4)
text = sublime.get_clipboard().expandtabs(tab_size)
sublime.set_clipboard(text)
This implements a new command copy_with_spaces which will perform a copy but modify the data on the way through so that any physical tab characters are replaced with the appropriate number of white space characters.
With that in place, you can add a custom key binding to use when you're copying code from Sublime to Jupyter to streamline things. An example might be:
{
"keys": ["shift+ctrl+c"],
"command": "copy_with_spaces",
}

Inserting comments into jupyter notebook

I hope this is not a redundant question, but I was not able to find a proper answer and tutorial. I am currently learning Data Science and therefore use kaggle competition for practice and jupyter notebook to tackle them (as it is visually more appealing to me). Now I stumbled upon an example kernel (see: http://nbviewer.jupyter.org/github/agconti/kaggle-titanic/blob/master/Titanic.ipynb#Data-Handling) is using comments, links and illustrations between his codes to give more context.
Is anybody aware of how to write such comments and remarks within jupyter? If so, do you have an online resource where I could learn this?
Thanks a bunch!
Yep - highlight a cell and click on the "Cell" dropdown menu and go to "Cell Type" and choose "Markdown". Then you can type any markdown text you'd like and it will render as such.
^^ Also there are shortcuts for changing cell types as well. Highlight a cell and press the esc key to change into "command" mode and press m. This changes it to a markdown cell. Press y to change it back to a code cell.
You can also do latex equations using dollar signs ($). There is documentation for this here
For markdown cells
[//]: # "Your comment in here."
allows to include a comment in jupyter notebook server version 6.0.1. See this discussion for more details on markdown comments.
Agree with #RSHAP. I just add the flow picture in the below.
select the active Cell > Cell Type > Markdown.
irrespective of the version of jupyter notebook you use, the following command should work on current cell
Pres ESC
then Press m
As mentioned in the above remarks, use markdown cells.
Once in a markdown cell, use #,##,###,#### for headings of different fonts. For bold, use **your_text_here**, and for italics use *your_text_here*. For writing equations and using latex commands, use $ symbol. Everything works just like in latex; you can even define your notations like you would normally do in Latex. For a more detailed and structured overview to format text In Jupyter, have a look at this website:
https://www.earthdatascience.org/courses/intro-to-earth-data-science/file-formats/use-text-files/format-text-with-markdown-jupyter-notebook/

How to edit markdown cell in jupyter-notebook ( Could not edit markdown cell in Jupyter notebook)

I got a strange problem with jupyter-notebook.
I was practicing with notebook which has markdown and code cells.
When I save and reopen the notebook, I can edit code cells but not the
markdown cells.
Attempts:
reload the page.
Make the notebook trusted.
Try to change the cell type from markdown to code or raw but still can not edit.
NOTE:
I can delete some letters on markdown but I can not add any letters.
Also if I hit enter it will create new lines, but I can not write anything there.
Question
How can we edit the markdown cell of a jupyter-notebook ?
In case anybody also encountered the same problem, I am keeping this question
and my solution to it, instead of deleting the question.
What I did is :
a) First go to markdown cell.
b) Double click the cell, now we can only delete the letters, can not edit it.
c) Go to command mode (press esc) and again come back to edit mode (Enter).
d) Now we can edit the markdown cell.
This solved my problem.
Just double click on the markdown cell. Edit what you want to and Run. It will reflect the changes. Save your notebook.

How to format text cells in Jupyter?

I would like to create a Jupyter notebook to make a tutorial.
When I go to the jupyter website and I try jupyter in the browser, there is already a nice python tutorial, with some cells used as text explanations and others as code:
Now I create a new notebook and I am able to create different cells and format them in 4 types:
Code
Markdown
Raw NBConvert
Heading
However none of them allow me to create the text explanations with white background as in the image above.
I tried formatting one cell as markdown and it's just keeping with the grey background.
Am I missing something? Thanks.
After creating those blocks you have to run them to give you that white background.
Press Ctrl + Enter inside the block.
For eg.
Click on a cell. Press Esc and then press 1
Now type this: "THIS IS A HEADING"
And then press Ctrl + Enter.
You will get this as an output with a white background (The image below is a bit dull):
In addition, by using the %%html magic command, you can type HTML in cells and get them rendered the way you want

Categories