Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the skills of Python data analysis?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the Python data analysis skills". In the daily operation, I believe many people have doubts about what Python data analysis skills they have. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what Python data analysis skills are there?" Next, please follow the editor to study!

1. Pandas Profiling

The effect of the tool is obvious. The following figure shows the result of a simple method called df.profile_report ():

You only need to install and import the Pandas Profiling package to use this tool.

two。 Drawing Pandas data using Cufflinks and Plotly

Most "experienced" data scientists or data analysts are familiar with matplotlib and pandas. In other words, you can quickly draw a simple pd.DataFrame or pd.Series by calling the .plot () method:

A little boring?

This is fine, but is it possible to draw an interactive, scalable, scalable panorama? It's time for Cufflinks* * to do it! (Cufflinks makes further packaging based on Plotly. )

To install Cufflinks in the environment, just run it in the terminal! Pip install cufflinks-- upgrade is fine. View the following figure:

The effect is much better!

Notice that the only change in the figure above is the import and setting of Cufflinks cf.go_offline (), which changes the .plot () method to .iplot ().

Other methods such as .scatter _ matrix () can also provide great visualization results:

Friends who need to do a lot of data visualization work can read the documents of Cufflinks and Plotly and find more ways.

Cufflinks documentation: https://plot.ly/ipython-notebooks/cufflinks/ Plotly documentation: https://plot.ly/

3. IPython Magic Command

IPython's "magic" is a series of enhancements to IPython based on the Python standard syntax. Magic commands include two methods: magic command (line magics): run on a single input line with the% prefix, and cell magic command (cell magics): run on multiple input lines with the% prefix. Here are some useful features provided by the IPython magic command:

% lsmagic: find all commands

If you only remember one magic order, it has to be this one. Executing the% lsmagic command provides a list of all available magic commands:

% debug: interactive debug

This is probably the most common magic command I use.

Most data scientists have encountered this situation: the block of code executed is break all the time, and you write 20 print () statements in despair, trying to output the contents of each variable. Then, when you finally fix the problem, you have to go back and delete all the print () statements again.

But you don't have to do that anymore. When you encounter a problem, simply execute the% debug command to execute any part of the code you want to run:

What happened in the picture above?

Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community

We have a function that takes a list as input and squares all even numbers.

We ran the function, but something went wrong. But we don't know what happened!

Use the% debug command for this function.

Let the debugger tell us the values of x and type (x).

The problem is obvious: we input 6 as a string into the function!

This is very useful for more complex functions.

% store: passing variables between notebook

That's a cool order, too. Suppose you spend some time cleaning the data in notebook, and now you want to test some functionality in another notebook, do you implement this function in the same notebook, or do you save the data and load it in another notebook? None of these operations are required after using the% store command! This command will store the variable, which you can retrieve in any other notebook:

% store [variable] stores variables.

% store-r [variable] reads / retrieves storage variables.

% who: lists all global variables.

Have you ever forgotten a variable name after assigning a value to it? Or accidentally delete the cell responsible for assigning values to variables? Using the% who command, you can get a list of all global variables:

%% time: timing magic command

Use this command to get all timing information. Simply apply the%% time command to any executable code and you will get the following output:

%% writefile: write cell contents to the file

This magic command is useful when you write a complex function or class in notebook and want to save it to an exclusive file. Simply add the%% writefile prefix to the cell of the function or class and the file name you want to save to:

As shown above, we can save the created function to a utils.py file, and then we can import it at will. You can do the same in other notebook, as long as you belong to the same directory as the utils.py file.

4. Formatting in Jupyter

This tool is cool! Jupyter takes into account the existence of the HTML / CSS format in markdown. Here are the features I use most frequently:

Blue, fashionable:

This is fancy!

Red, slightly flustered:

This is baaaaad!

Green, calm:

This is gooood!

The following figure shows how they work:

This is very useful when you want to present some findings in Notebook format!

5. Jupyter shortcut key

To learn and learn keyboard shortcuts, you can use the command panel: Ctrl + Shift + P to get a list of all the features of notebook. Here are some of the most basic commands:

Esc: enter command mode. In command mode, you can use the arrow keys to navigate within notebook.

In command mode:

An and B: insert a new cell above or below the current cell (Above) or below (Below).

M: the current cell is transferred to Markdown state.

Y: the current cell is transferred to the code state.

Dminute D: deletes the current cell.

Enter: the current cell returns to edit mode.

In edit mode:

Shift + Tab: provides a document string (document) for the objects you type in the current cell. Continue to use this shortcut key to recycle the document mode.

Ctrl + Shift + -: splits the current cell at the cursor.

Esc + F: find and replace the code (excluding output).

Esc + O: toggles cell output.

Select multiple cells:

Shift + Down and Shift + Up: check the cells below or above.

Shift + M: merge selected cells.

Note that when multiple cells are selected, you can batch delete / copy / cut / paste / run.

6. To make a unit have multiple outputs at the same time in Jupyter (or IPython)

Have you ever wanted to show pandas DataFrame's .head () and .tail (), but had to give up halfway because it was too troublesome to create an extra unit of code that runs the .tail () method? Now don't be afraid, you can use the following lines of code to show the output you want to show:

From IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all"

The following figure shows the results of multiple outputs:

7. Create slides instantly for Jupyter Notebook

With RISE, you can instantly turn Jupyter Notebook into a slide with just one button. And notebook is still active, you can perform real-time coding while showing slides!

To use the tool, you only need to install RISE through conda or pip.

Conda install-c conda-forge rise

Or

Pip install RISE

Now you can click the new button to create a good slide for notebook:

At this point, the study of "what are the Python data analysis skills" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report