{"id":87307,"date":"2020-10-12T14:39:19","date_gmt":"2020-10-12T11:39:19","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/10-simple-python-tips-to-speed-up-your-data-analysis\/"},"modified":"2020-10-12T14: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:\/\/buradabiliyorum.com\/en\/10-simple-python-tips-to-speed-up-your-data-analysis\/","title":{"rendered":"#10 simple Python tips to speed up your data analysis"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2598f8b4f64\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2598f8b4f64\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/10-simple-python-tips-to-speed-up-your-data-analysis\/#A_dash_of_magic\" >A dash of magic<\/a><\/li><\/ul><\/nav><\/div>\n<p>&#8220;<strong>#10 simple Python tips to speed up your data analysis<\/strong>&#8221;<\/p>\n<div>\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\"><span class=\"ez-toc-section\" id=\"A_dash_of_magic\"><\/span>A dash of magic<span class=\"ez-toc-section-end\"><\/span><\/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\u00a0are 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\u00a0<code>%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 loading=\"lazy\" decoding=\"async\" class=\"uz va t u v ik aj c lazy\" alt=\"Image for post\" width=\"718\" height=\"330\" src=\"https:\/\/miro.medium.com\/max\/718\/1*cK6E96d4e5R6wBrQVkd8nA.png\" data-lazy=\"true\"\/><figcaption><a rel=\"nofollow noopener noreferrer\" target=\"_blank\" 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\"\/><\/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:\u00a0<em class=\"mt\">line magics<\/em>, which are prefixed by a single\u00a0<code>%<\/code>\u00a0character and operate on a single line of input, and\u00a0<em class=\"mt\">cell magics<\/em>, which are associated with the double\u00a0<code>%%<\/code>\u00a0prefix 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<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\u00a0<a rel=\"nofollow noopener noreferrer\" target=\"_blank\" class=\"cj iy\" href=\"https:\/\/en.wikipedia.org\/wiki\/Pastebin\">Pastebin<\/a>\u00a0and 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\u00a0pastebin\u00a0albeit\u00a0with 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 <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">script<\/a>\u00a0<code>file.py<\/code><span>\u00a0<\/span>with the following content:<span id=\"e7bb\" class=\"cd lj kf ff lg b av lx ly s lz\" data-selectable-paragraph=\"\"\/><\/p>\n<p data-selectable-paragraph=\"\">\n<figure class=\"post-image post-mediaBleed alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1322788 lazy\" alt=\"\" width=\"674\" height=\"88\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.30-PM.png\" data-lazy=\"true\" 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\u00a0%pastebin\u00a0in 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 loading=\"lazy\" decoding=\"async\" class=\"uz va t u v ik aj c lazy\" sizes=\"auto, 501px\" alt=\"Image for post\" width=\"501\" height=\"143\" src=\"https:\/\/miro.medium.com\/max\/501\/1*aXqVXL-5WZFltIGbUidqpg.png\" data-lazy=\"true\" 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<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>\u00a0<\/span><code>%matplotlib inline<\/code>\u00a0function is used to render the static matplotlib plots within the Jupyter notebook. Try replacing the<span>\u00a0<\/span><code>inline<\/code>\u00a0part with<span>\u00a0<\/span><code>notebook\u00a0<\/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 loading=\"lazy\" decoding=\"async\" class=\"uz va t u v ik aj c lazy\" alt=\"Image for post\" width=\"834\" height=\"407\" src=\"https:\/\/miro.medium.com\/max\/834\/1*IAtw6rydG7o58yy2EyzCRA.png\" data-lazy=\"true\"\/><figcaption><a rel=\"nofollow noopener noreferrer\" target=\"_blank\" 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\"\/><\/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\u00a0<code>%run<\/code>\u00a0function runs a python script inside a notebook.<\/p>\n<p data-selectable-paragraph=\"\">\n<figure class=\"post-image post-mediaBleed alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1322789 lazy\" alt=\"\" width=\"680\" height=\"56\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" src=\"https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/Screen-Shot-2020-10-12-at-12.28.56-PM.png\" data-lazy=\"true\" 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<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>%%writefile<\/code>\u00a0writes the contents of a cell to a file. Here the code will be written to a file named\u00a0foo.py\u00a0and 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 loading=\"lazy\" decoding=\"async\" class=\"uz va t u v ik aj c lazy\" sizes=\"auto, 333px\" alt=\"Image for post\" width=\"333\" height=\"102\" src=\"https:\/\/miro.medium.com\/max\/333\/1*5p2-kMkzKnBR7WARU4u_Wg.png\" data-lazy=\"true\" 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 loading=\"lazy\" decoding=\"async\" class=\"uz va t u v ik aj c lazy\" sizes=\"auto, 379px\" alt=\"Image for post\" width=\"379\" height=\"143\" src=\"https:\/\/miro.medium.com\/max\/379\/1*G5JF-JXjEjX8AaoNpEk-aQ.png\" data-lazy=\"true\" 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<\/div>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener noreferrer\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/thenextweb.com\/syndication\/2020\/10\/12\/10-simple-python-tips-to-speed-up-your-data-analysis\/\" target=\"_blank\" rel=\"noopener noreferrer\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#10 simple Python tips to speed up your data analysis&#8221; A dash of magic Magic commands\u00a0are 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\u00a0%lsmagic. List of all available magic functions Magic&#8230;<\/p>\n","protected":false},"author":1,"featured_media":87308,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/img-cdn.tnwcdn.com\/image\/tnw?filter_last=1&fit=1280,640&url=https:\/\/cdn0.tnwcdn.com\/wp-content\/blogs.dir\/1\/files\/2020\/10\/image-1-6.png&signature=02d80d44e2d54e45eb9cc5aac1f8e6a0","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[75432,75430,73706,72781,70759,75431],"class_list":["post-87307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-data-analysis","tag-data-set","tag-python-programming-language","tag-source-code","tag-tech","tag-visualization"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/87307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=87307"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/87307\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/87308"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=87307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=87307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=87307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}