{"id":281,"date":"2020-10-12T11:39:19","date_gmt":"2020-10-12T11:39:19","guid":{"rendered":"https:\/\/thenextweb.com\/?p=1322777"},"modified":"2020-10-12T11:39:19","modified_gmt":"2020-10-12T11:39:19","slug":"10-simple-python-tips-to-speed-up-your-data-analysis","status":"publish","type":"post","link":"https:\/\/www.londonchiropracter.com\/?p=281","title":{"rendered":"10 simple Python tips to speed up your data analysis"},"content":{"rendered":"<br \/>\n<h2 id=\"7b59\" class=\"ke kf ff at kg kh ki kj kk kl km kn ko kp kq kr ks kt ku kv kw cd\">A dash of magic<\/h2>\n<p id=\"c195\" class=\"iz ja ff jb b jc kx je jf jg ky ji jj jk kz jm jn jo la jq jr js lb ju jv jw ex cd\" data-selectable-paragraph>Magic commands&nbsp;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&nbsp;<code class=\"io ld le lf lg b\">%lsmagic<\/code>.<\/p>\n<figure class=\"hz ia ib ic id hp eq er paragraph-image\">\n<div class=\"ig ih cf ii aj\">\n<div class=\"eq er mr\">\n<div class=\"in s cf io\">\n<div class=\"ms iq s\">\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"uz va t u v ik aj c lazy\" src=\"https:\/\/miro.medium.com\/max\/718\/1*cK6E96d4e5R6wBrQVkd8nA.png\" alt=\"Image for post\" width=\"718\" height=\"330\" data-lazy=\"true\"><figcaption><a href=\"https:\/\/thenextweb.com\/syndication\/2020\/10\/12\/10-simple-python-tips-to-speed-up-your-data-analysis\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fthenextweb.com%2Fsyndication%2F2020%2F10%2F12%2F10-simple-python-tips-to-speed-up-your-data-analysis%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: List of all available magic functions\" data-title=\"Share List of all available magic functions on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share List of all available magic functions on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"><\/i><\/a>List of all available magic functions<\/figcaption><\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p id=\"7d0f\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>Magic commands are of two kinds:&nbsp;<em class=\"mt\">line magics<\/em>, which are prefixed by a single&nbsp;<code class=\"io ld le lf lg b\">%<\/code>&nbsp;character and operate on a single line of input, and&nbsp;<em class=\"mt\">cell magics<\/em>, which are associated with the double&nbsp;<code class=\"io ld le lf lg b\">%%<\/code>&nbsp;prefix and operate on multiple lines of input. Magic functions are callable without having to type the initial % if set to 1.<\/p>\n<p id=\"96cb\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>Let\u2019s look at some of them that might be useful in common data analysis tasks:<\/p>\n<ul class>\n<li id=\"483b\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw mu mv mw cd\" data-selectable-paragraph>% pastebin<\/li>\n<\/ul>\n<p id=\"791b\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>%pastebin uploads code to&nbsp;<a class=\"cj iy\" href=\"https:\/\/en.wikipedia.org\/wiki\/Pastebin\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Pastebin<\/a>&nbsp;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&nbsp;pastebin&nbsp;albeit&nbsp;with version control.<\/p>\n<p id=\"c0c6\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>Consider a python script&nbsp;<code class=\"io ld le lf lg b\">file.py<\/code><span>&nbsp;<\/span>with the following content:<span id=\"e7bb\" class=\"cd lj kf ff lg b av lx ly s lz\" data-selectable-paragraph><\/span><\/p>\n<p data-selectable-paragraph>\n<figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1322788 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.30-PM.png\" alt width=\"674\" height=\"88\" sizes=\"(max-width: 674px) 100vw, 674px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.30-PM.png 674w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.30-PM-280x37.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.30-PM-540x71.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.30-PM-270x35.png 270w\"><\/figure>\n<\/p>\n<p id=\"a955\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>Using&nbsp;%pastebin&nbsp;in Jupyter Notebook generates a pastebin url.<\/p>\n<figure class=\"hz ia ib ic id hp eq er paragraph-image\">\n<div class=\"eq er mx\">\n<div class=\"in s cf io\">\n<div class=\"my iq s\"><img decoding=\"async\" loading=\"lazy\" class=\"uz va t u v ik aj c lazy\" src=\"https:\/\/miro.medium.com\/max\/501\/1*aXqVXL-5WZFltIGbUidqpg.png\" sizes=\"501px\" alt=\"Image for post\" width=\"501\" height=\"143\" data-lazy=\"true\" data-srcset=\"https:\/\/miro.medium.com\/max\/276\/1*aXqVXL-5WZFltIGbUidqpg.png 276w, https:\/\/miro.medium.com\/max\/501\/1*aXqVXL-5WZFltIGbUidqpg.png 501w\"><\/div>\n<\/div>\n<\/div>\n<\/figure>\n<ul>\n<li>%matplotlib notebook<\/li>\n<\/ul>\n<p id=\"50d8\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>The<span>&nbsp;<\/span><code class=\"io ld le lf lg b\">%matplotlib inline<\/code>&nbsp;function is used to render the static matplotlib plots within the Jupyter notebook. Try replacing the<span>&nbsp;<\/span><code class=\"io ld le lf lg b\">inline<\/code>&nbsp;part with<span>&nbsp;<\/span><code class=\"io ld le lf lg b\">notebook&nbsp;<\/code>to get zoom-able &amp; resize-able plots, easily. Make sure the function is called before importing the matplotlib library.<\/p>\n<figure class=\"hz ia ib ic id hp eq er paragraph-image\">\n<div class=\"ig ih cf ii aj\">\n<div class=\"eq er mz\">\n<div class=\"in s cf io\">\n<div class=\"na iq s\">\n<figure class=\"post-image post-mediaBleed aligncenter\"><img decoding=\"async\" loading=\"lazy\" class=\"uz va t u v ik aj c lazy\" src=\"https:\/\/miro.medium.com\/max\/834\/1*IAtw6rydG7o58yy2EyzCRA.png\" alt=\"Image for post\" width=\"834\" height=\"407\" data-lazy=\"true\"><figcaption><a href=\"https:\/\/thenextweb.com\/syndication\/2020\/10\/12\/10-simple-python-tips-to-speed-up-your-data-analysis\/#\" data-url=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fthenextweb.com%2Fsyndication%2F2020%2F10%2F12%2F10-simple-python-tips-to-speed-up-your-data-analysis%2F&amp;via=thenextweb&amp;related=thenextweb&amp;text=Check out this picture on: %matplotlib inline vs %matplotlib notebook\" data-title=\"Share %matplotlib inline vs %matplotlib notebook on Twitter\" data-width=\"685\" data-height=\"500\" class=\"post-image-share popitup\" title=\"Share %matplotlib inline vs %matplotlib notebook on Twitter\"><i class=\"icon icon--inline icon--twitter--dark\"><\/i><\/a>%matplotlib inline vs %matplotlib notebook<\/figcaption><\/figure>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p id=\"bd4d\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>The&nbsp;<code class=\"io ld le lf lg b\">%run<\/code>&nbsp;function runs a python script inside a notebook.<\/p>\n<p data-selectable-paragraph>\n<figure class=\"post-image post-mediaBleed alignnone\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-1322789 lazy\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.56-PM.png\" alt width=\"680\" height=\"56\" sizes=\"(max-width: 680px) 100vw, 680px\" data-lazy=\"true\" data-srcset=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.56-PM.png 680w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.56-PM-280x23.png 280w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.56-PM-540x44.png 540w, https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.56-PM-270x22.png 270w\"><\/figure>\n<\/p>\n<ul class>\n<li id=\"3ed9\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw mu mv mw cd\" data-selectable-paragraph>%%writefile<\/li>\n<\/ul>\n<p id=\"097b\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph><code class=\"io ld le lf lg b\">%%writefile<\/code>&nbsp;writes the contents of a cell to a file. Here the code will be written to a file named&nbsp;foo.py&nbsp;and saved in the current directory.<\/p>\n<figure class=\"hz ia ib ic id hp eq er paragraph-image\">\n<div class=\"eq er nb\">\n<div class=\"in s cf io\">\n<div class=\"nc iq s\"><img decoding=\"async\" loading=\"lazy\" class=\"uz va t u v ik aj c lazy\" src=\"https:\/\/miro.medium.com\/max\/333\/1*5p2-kMkzKnBR7WARU4u_Wg.png\" sizes=\"333px\" alt=\"Image for post\" width=\"333\" height=\"102\" data-lazy=\"true\" data-srcset=\"https:\/\/miro.medium.com\/max\/276\/1*5p2-kMkzKnBR7WARU4u_Wg.png 276w, https:\/\/miro.medium.com\/max\/333\/1*5p2-kMkzKnBR7WARU4u_Wg.png 333w\"><\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p id=\"db8a\" class=\"iz ja ff jb b jc jd je jf jg jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw ex cd\" data-selectable-paragraph>The %%latex function renders the cell contents as LaTeX. It is useful for writing mathematical formulae and equations in a cell.<\/p>\n<figure class=\"hz ia ib ic id hp eq er paragraph-image\">\n<div class=\"eq er nd\">\n<div class=\"in s cf io\">\n<div class=\"ne iq s\"><img decoding=\"async\" loading=\"lazy\" class=\"uz va t u v ik aj c lazy\" src=\"https:\/\/miro.medium.com\/max\/379\/1*G5JF-JXjEjX8AaoNpEk-aQ.png\" sizes=\"379px\" alt=\"Image for post\" width=\"379\" height=\"143\" data-lazy=\"true\" data-srcset=\"https:\/\/miro.medium.com\/max\/276\/1*G5JF-JXjEjX8AaoNpEk-aQ.png 276w, https:\/\/miro.medium.com\/max\/379\/1*G5JF-JXjEjX8AaoNpEk-aQ.png 379w\"><\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p> <a href=\"https:\/\/thenextweb.com\/syndication\/2020\/10\/12\/10-simple-python-tips-to-speed-up-your-data-analysis\/\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A dash of magic Magic commands&nbsp;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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":282,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/posts\/281"}],"collection":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=281"}],"version-history":[{"count":0,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/posts\/281\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=\/wp\/v2\/media\/282"}],"wp:attachment":[{"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.londonchiropracter.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}