10 simple Python tips to speed up your data analysis | Tricks and Tips | The latest technology and digital news on the web
  • News
  • Web Design
  • Google and SEO
  • Mobile
  • Social Networks
  • Tricks and Tips
  • Free Website
  • Search
  • Menu
  • Contact

  • News

  • Web Design

  • Google and SEO

  • Mobile

  • Social Networks

  • Tricks and Tips

  • Free Website

The latest technology and digital news on the web

10 simple Python tips to speed up your data analysis

October 12, 2020

The report can also be exported into an interactive HTML file with the afterward code.

Tips and tricks, abnormally in the programming world, can be very useful. Sometimes a little hack can be both time and life-saving. A minor adjustment or add-on can sometimes prove to be a Godsend and can be a real abundance booster. So, here are some of my admired tips and tricks I’ve used and aggregate calm in the form of this article. Some may be fairly known and some may be new, but I’m sure they’ll come in pretty handy the next time you work on a data assay project.

Profiling the ‘pandas’ dataframe

Profilingis a action that helps us accept our data, and Pandas Profiling is a python amalgamation that does absolutely that. It’s a simple and fast way to accomplish basic data assay of a Pandas Dataframe. The pandas df.describe()and df.info()functions are commonly used as a first step in the EDA process. However, it only gives a very basic overview of the data and doesn’t help much in the case of large data sets. The Pandas Profiling function, on the other hand, extends the pandas DataFrame with df.profile_report() for quick data analysis. It displays a lot of advice with a single line of code and that too in an alternate HTML report.

For a given dataset the pandas profiling amalgamation computes the afterward statistics:

webrok

Installation

webrok

The report can also be exported into an interactive HTML file with the afterward code.

webrok

Refer to this documentation for more capacity and examples.

Bringing interactivity to pandas plots

Pandas has a built-in .plot() function as part of the DataFrame class. However, the visualizations rendered with this action aren’t alternate and that makes it less appealing. On the contrary, the ease to plot charts with pandas.DataFrame.plot() function also cannot be ruled out. What if we could plot alternate plotly like charts with pandas after having to make major modifications to the code? Well, you can absolutely do that with the help of Cufflinks library.

Cufflinks library binds the power of plotly with the adaptability of pandas for easy plotting. Let’s now see how we can install the library and get it alive in pandas.

Installation

webrok

webrok
webrok

The decision on the right shows the static chart while the left chart is alternate and more abundant and all this after any major change in the syntax.

Click here for more examples.

A dash of magic

Magic commands are a set of acceptable functions in Jupyter Notebooks that are advised to solve some of the common problems in accepted data analysis. You can see all accessible magics with the help of %lsmagic.

webrok

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

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

  • % pastebin

%pastebin uploads code to Pastebin and allotment the URL. Pastebin is an online agreeable hosting account 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 adaptation control.

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

webrok

  • %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 action is called before importing the matplotlib library.

webrok
  • %run

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

webrok

  • %%latex

The %%latex action renders the cell capacity as LaTeX. It is useful for autograph algebraic formulae and equations in a cell.

webrok

Finding and eliminating errors

The interactive debugger is also a magic action but I have given it a class of its own. If you get an barring while active the code cell, type ?bug in a new line and run it. This opens an alternate debugging ambiance that brings you to the position where the barring has occurred. You can also check for the values of variables assigned in the affairs and also accomplish operations here. To exit the debugger hit q.

webrok

Printing can be pretty too

If you want to aftermath aesthetically adorable representations of your data structures, pprint is the go-to module. It is abnormally useful when press dictionaries or JSON data. Let’s have a look at an archetype which uses both print and pprint to affectation the output.

webrok
webrok

Making the notes stand out

We can use alert/Note boxes in your Jupyter Notebooks to highlight commodity important or annihilation that needs to stand out. The color of the note depends upon the type of alert that is specified. Just add any or all of the afterward codes in a cell that needs to be highlighted.

  • Blue Alert Box: info

webrok

  • Yellow Alert Box: Warning
webrok



  • Red Alert Box: Danger
webrok






Printing all the outputs of a cell

Consider a cell of Jupyter Anthology absolute the afterward lines of code:

webrok

Running python scripts with the ‘i’ option.

A archetypal way of active a python script from the command line is: python hello.py. However, if you add an additional -i while active the same script e.g python -i hello.py it offers more advantages. Let’s see how.

  • Firstly, once the end of the affairs is reached, python doesn’t exit the interpreter. As such we can check the values of the variables and the definiteness of the functions authentic in our program.
webrok
  • Secondly, we can easily invoke a python debugger since we are still in the analyst by:

This will bring us to the position where the barring has occurred and we can then work upon the code.

The original source of the hack.

Commenting out code automatically

Ctrl/Cmd / comments out called lines in the cell by automatically. Hitting the aggregate again will uncomment the same line of code.

webrok

To delete is human, to restore divine

Have you ever accidentally deleted a cell in a Jupyter Notebook? If yes then here is a adjustment that can undo that delete action.

  • In case you have deleted the capacity of a cell, you can easily balance it by hitting CTRL/CMD Z
  • If you need to balance an entire deleted cell hit ESC Z or EDIT > Undo Delete Cells
webrok

In this article, I’ve listed the main tips I have aggregate while alive with Python and Jupyter Notebooks. I’m sure these simple hacks will be of use to you at some point in your career. Till then, happy coding!


Read next: AI helps aftermath world's better 3D map of the cosmos

TechData setVisualizationData analysisSource codePython (programming language)

  • Go back
  • Tricks and Tips
Webrok

Hottest related news

No articles found on this category.
No articles found on this category.

Newsletter

Enter your email address

About

WebRok is a leading digital technology media property, dedicated to obsessively comunicating web news, reviewing new Internet products, and breaking digital news.

Links

  • www.diretoriode.com
  • www.frontbest.com
  • www.brasileu.com
  • www.frontstars.com
  • www.outlet-auto.com
  • Advertise

Categories

  • News
  • Web Design
  • Google and SEO
  • Mobile
  • Social Networks
  • Tricks and Tips
  • Free Website

  • Facebook

All rights reserved to www.webrok.com - 2012-2016 - Web Design: GoFox