Category: Python

  • 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/”] # 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 […]