Category: Python

When coding for my thesis, I encounter many small problems. Here I collect my solutions, if I could solve them without asking on Stack Overflow.


  • How add a Python virtual environment to your Jupyter Kernel list

    Say you have a custom virtual environment named myEnv, in which you have meticulously setup an old Python version, together with some arcane packages (activated by source .myEnv/bin/activate), you must install package ipykernel to make this environment capable of interfacing with your host system Python installation in which you have Jupyter installed: Once that’s done,…

  • How to create a nicely formatted Excel table from a pandas DataFrame using openpyxl

    How to create a nicely formatted Excel table from a pandas DataFrame using openpyxl

    When I want to save the current state of a pandas DataFrame for “manual consumption”, I often write df.to_excel(‘foo.xlsx’) within my IPython session or Jupyter Notebook. However, the default style does not look pretty and often needs manual adjustments (e.g. column widths) to be usable. If you want to create custom reports from pandas, you…

  • My Python setup

    My Python setup

    In this post, I summarise my custom settings for my IPython, Matplotlib and IPython Notebook for my Windows machine at work. IPython First some aesthetic preferences: [code lang=”python” title=”.ipython/profile_default/ipython_config.py”] # select qt backend for plotting from terminal from IPython.terminal.ipapp import TerminalIPythonApp TerminalIPythonApp.matplotlib=’qt’ c = get_config() # bigger plots in IPython notebooks c.InlineBackend.rc = {‘figure.figsize’: (16.0,…

  • How to change the default matplotlib font

    The default fonts for matplotlib are set in file matplotlibrc in the folder $USER_HOME/.matplotlib. You can find them here, depending on your operating system: Windows: C:\Users\YourName\.matplotlib\matplotlibrc Linux: /home/YourName/.matplotlib/matplotlibrc Within the file, search for the font section, and uncomment (remove the hash symbol # at beginning of line) or add the following settings as desired. In…

  • How to autoreload packages while using them in IPython

    I use IPython to interactively use and debug code that I edit in a text editor at the same time. Unfortunately, Python does not automatically reload packages and functions after an initial import foo, simply for performance reasons. Fortunately, there is a solution: the IPython extension autoreload does what its name says: either all (how…