“ImportError: No module named” when trying to run Python script

This issue arises due to the ways in which the command line IPython interpreter uses your current path vs. the way a separate process does (be it an IPython notebook, external process, etc). IPython will look for modules to import that are not only found in your sys.path, but also on your current working directory. … Read more

How to read a .xlsx file using the pandas Library in iPython?

I usually create a dictionary containing a DataFrame for every sheet: xl_file = pd.ExcelFile(file_name) dfs = {sheet_name: xl_file.parse(sheet_name) for sheet_name in xl_file.sheet_names} Update: In pandas version 0.21.0+ you will get this behavior more cleanly by passing sheet_name=None to read_excel: dfs = pd.read_excel(file_name, sheet_name=None) In 0.20 and prior, this was sheetname rather than sheet_name (this is … Read more

ipython notebook clear cell output in code

You can use IPython.display.clear_output to clear the output of a cell. from IPython.display import clear_output for i in range(10): clear_output(wait=True) print(“Hello World!”) At the end of this loop you will only see one Hello World!. Without a code example it’s not easy to give you working code. Probably buffering the latest n events is a … Read more

collapse cell in jupyter notebook

UPDATE: The newer jupyter-lab is a more modern and feature-rich interface which supports cell folding by default. See @intsco’s answer below UPDATE 2 Since jupyter-lab now also supports extensions, you can extend the built-in cell-folding functionality with the Collapsible_Headings extension. Original answer: The jupyter contrib nbextensions Python package contains a code-folding extension that can be … Read more

How to embed HTML into IPython output?

This seems to work for me: from IPython.core.display import display, HTML display(HTML(‘<h1>Hello, world!</h1>’)) The trick is to wrap it in display as well. Source: http://python.6.x6.nabble.com/Printing-HTML-within-IPython-Notebook-IPython-specific-prettyprint-tp5016624p5016631.html Edit: from IPython.display import display, HTML In order to avoid: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display

How to run an .ipynb Jupyter Notebook from terminal?

nbconvert allows you to run notebooks with the –execute flag: jupyter nbconvert –execute <notebook> If you want to run a notebook and produce a new notebook, you can add –to notebook: jupyter nbconvert –execute –to notebook <notebook> Or if you want to replace the existing notebook with the new output: jupyter nbconvert –execute –to notebook … Read more

What is the difference between Python and IPython?

ipython is an interactive shell built with python. From the project website: IPython provides a rich toolkit to help you make the most out of using Python, with: Powerful Python shells (terminal and Qt-based). A web-based notebook with the same core features but support for code, text, mathematical expressions, inline plots and other rich media. … Read more

How to display pandas DataFrame of floats using a format string for columns?

import pandas as pd pd.options.display.float_format=”${:,.2f}”.format df = pd.DataFrame([123.4567, 234.5678, 345.6789, 456.7890], index=[‘foo’,’bar’,’baz’,’quux’], columns=[‘cost’]) print(df) yields cost foo $123.46 bar $234.57 baz $345.68 quux $456.79 but this only works if you want every float to be formatted with a dollar sign. Otherwise, if you want dollar formatting for some floats only, then I think you’ll have … Read more