Londonchiropracter.com

This domain is available to be leased

Menu
Menu

10 simple Python tips to speed up your data analysis

Posted on October 12, 2020 by admin

A dash of magic

Magic commands are a set of convenient functions in Jupyter Notebooks that are designed to solve some of the common problems in standard data analysis. You can see all available magics with the help of %lsmagic.

Image for post
List of all available magic functions

Magic commands are of two kinds: line magics, which are prefixed by a single % character and operate on a single line of input, and cell magics, which are associated with the double %% prefix and operate on multiple lines of input. Magic functions are callable without having to type the initial % if set to 1.

Let’s look at some of them that might be useful in common data analysis tasks:

  • % pastebin

%pastebin uploads code to Pastebin and returns the URL. Pastebin is an online content hosting service where we can store plain text like source code snippets and then the URL can be shared with others. In fact, Github gist is also akin to pastebin albeit with version control.

Consider a python script file.py with the following content:

Using %pastebin in Jupyter Notebook generates a pastebin url.

Image for post
  • %matplotlib notebook

The %matplotlib inline function is used to render the static matplotlib plots within the Jupyter notebook. Try replacing the inline part with notebook to get zoom-able & resize-able plots, easily. Make sure the function is called before importing the matplotlib library.

Image for post
%matplotlib inline vs %matplotlib notebook

The %run function runs a python script inside a notebook.

  • %%writefile

%%writefile writes the contents of a cell to a file. Here the code will be written to a file named foo.py and saved in the current directory.

Image for post

The %%latex function renders the cell contents as LaTeX. It is useful for writing mathematical formulae and equations in a cell.

Image for post

Source

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • A humanoid robot just beat the human half-marathon world record by seven minutes in Beijing
  • Trump wants to stop states from regulating AI. States and Congress keep saying no.
  • Google is in talks with Marvell to build custom AI inference chips as it diversifies beyond Broadcom
  • Stanford’s AI Index finds China has nearly closed the performance gap with the US despite spending 23 times less
  • Threads is redesigning its website and finally adding direct messages to the desktop

Recent Comments

    Archives

    • April 2026
    • March 2026
    • February 2026
    • January 2026
    • December 2025
    • September 2025
    • August 2025
    • July 2025
    • June 2025
    • May 2025
    • April 2025
    • March 2025
    • February 2025
    • January 2025
    • December 2024
    • November 2024
    • October 2024
    • September 2024
    • August 2024
    • July 2024
    • June 2024
    • May 2024
    • April 2024
    • March 2024
    • February 2024
    • January 2024
    • December 2023
    • November 2023
    • October 2023
    • September 2023
    • August 2023
    • July 2023
    • June 2023
    • May 2023
    • April 2023
    • March 2023
    • February 2023
    • January 2023
    • December 2022
    • November 2022
    • October 2022
    • September 2022
    • August 2022
    • July 2022
    • June 2022
    • May 2022
    • April 2022
    • March 2022
    • February 2022
    • January 2022
    • December 2021
    • November 2021
    • October 2021
    • September 2021
    • August 2021
    • July 2021
    • June 2021
    • May 2021
    • April 2021
    • March 2021
    • February 2021
    • January 2021
    • December 2020
    • November 2020
    • October 2020

    Categories

    • Uncategorized

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    ©2026 Londonchiropracter.com | Design: Newspaperly WordPress Theme