日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

使用python数据分析_如何使用Python提升您的数据分析技能

發(fā)布時(shí)間:2023/11/29 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用python数据分析_如何使用Python提升您的数据分析技能 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

使用python數(shù)據(jù)分析

If you're learning Python, you've likely heard about sci-kit-learn, NumPy and Pandas. And these are all important libraries to learn. But there is more to them than you might initially realize.

如果您正在學(xué)習(xí)Python,則可能聽(tīng)說(shuō)過(guò)sci-kit-learn,NumPy和Pandas。 這些都是需要學(xué)習(xí)的重要庫(kù)。 但是他們所擁有的比您最初想象的要多。

There are numerous tips and tricks in the world of Python that can help you speed up your tasks in data science, improve your code, and also help you to write code more efficiently.

Python領(lǐng)域中有許多技巧和竅門(mén),可以幫助您加快數(shù)據(jù)科學(xué)中的任務(wù),改善代碼并還可以更有效地編寫(xiě)代碼。

So I decided to compile some of the most valuable data analysis tips in this article for you.

因此,我決定為您編譯一些最有價(jià)值的數(shù)據(jù)分析技巧。

在Pandas中剖析數(shù)據(jù)框 (Profile dataframes in Pandas)

The primary role or purpose of profiling is to get a clear understanding of the data. And this is what the Python package, Pandas Profiling, does. This method is straightforward and fast in performing data analysis of dataframes in Pandas.

概要分析的主要作用或目的是對(duì)數(shù)據(jù)有清晰的了解。 這就是Python程序包Pandas Profiling所做的。 該方法在對(duì)Pandas中的數(shù)據(jù)幀執(zhí)行數(shù)據(jù)分析時(shí)非常簡(jiǎn)單快捷。

The exploratory data analysis process includes the Pandas df.info()functions and df.describe() as the first steps. But you only get a basic data overview, which might not be very helpful if you're dealing with a large data set.

探索性數(shù)據(jù)分析過(guò)程包括熊貓df.info()函數(shù)和df.describe()作為第一步。 但是您只會(huì)得到基本的數(shù)據(jù)概述,如果您要處理大量數(shù)據(jù)集,這可能不會(huì)很有幫助。

Pandas’s profiling function also extends the dataframe of Pandas with the df.profile_report(), which helps you quickly analyze data. It displays plenty of information in just one line of code, which also happens to be an HTML report that's interactive.

Pandas的分析功能還使用df.profile_report()擴(kuò)展了Pandas的數(shù)據(jù)框,該功能可幫助您快速分析數(shù)據(jù)。 它僅用一行代碼顯示大量信息,而這恰好是交互式HTML報(bào)告。

For a set of data, Pandas profiling computes these statistics:

對(duì)于一組數(shù)據(jù),Pandas分析會(huì)計(jì)算以下統(tǒng)計(jì)信息:

使熊貓圖更具互動(dòng)性 (Make pandas plots more interactive)

The built-in plot() function of Pandas is also one of the Dataframe classes. However, this function offers visualizations that are not very interactive, and so do not appeal much to a data science audience.

Pandas的內(nèi)置plot()函數(shù)也是Dataframe類(lèi)之一。 但是,此功能提供的可視化效果不是很互動(dòng),因此對(duì)數(shù)據(jù)科學(xué)的受眾吸引力不大。

On the other hand, it is easy to plot a chart with the Pandas.DataFrame.plot() function. The question then is, how do we plot interactive charts like Plotly using Pandas and without making significant changes to the code?

另一方面,使用Pandas.DataFrame.plot()函數(shù)可以很容易地繪制圖表。 然后的問(wèn)題是,如何在不對(duì)代碼進(jìn)行重大更改的情況下使用Pandas繪制交互式圖表(如Plotly)?

You can do this with the Cufflinks library, which binds Plotly’s power with Pandas's flexibility for plotting quickly.

您可以使用Cufflinks庫(kù)來(lái)做到這一點(diǎn),該庫(kù)將Plotly的功能與Pandas的靈活性相結(jié)合,可以快速進(jìn)行繪圖。

You can see the result in the images below.

您可以在下面的圖像中看到結(jié)果。

Both visualizations show the same things. The first visualization is a static chart, while the second one is a more interactive chart (and it also provides more details than the first one). Yet, we got this without making any significant changes to the syntax.

兩種可視化都顯示相同的內(nèi)容。 第一個(gè)可視化是靜態(tài)圖表,而第二個(gè)可視化是更具交互性的圖表(它還提供了比第一個(gè)圖表更多的詳細(xì)信息)。 但是,我們?cè)跊](méi)有對(duì)語(yǔ)法進(jìn)行任何重大更改的情況下獲得了此代碼。

魔術(shù)命令 (Magic commands)

The tag ‘Magic Commands’ refers to a set of functions in Jupyter Notebooks. They created this set of features to solve the many common problems that are experienced in standard data analysis.

標(biāo)簽“ Magic Commands”指的是Jupyter Notebook中的一組功能。 他們創(chuàng)建了這組功能來(lái)解決標(biāo)準(zhǔn)數(shù)據(jù)分析中遇到的許多常見(jiàn)問(wèn)題。

There are two kinds of Magic commands. First, there are the line magics - those that have a prefix of the % character. They also operate on one line of input.

有兩種Magic命令。 首先,有線魔術(shù)-帶有%字符前綴的魔術(shù)。 它們還可以在一行輸入上運(yùn)行。

The second kind are the cell magics - denoted by the double %% prefix. They work on more than one input line. If you set it to 1, you'll call the magic functions without needing to type the initial %.

第二種是細(xì)胞魔術(shù)-由雙%%前綴表示。 它們?cè)诙鄠€(gè)輸入行上工作。 如果將其設(shè)置為1,則無(wú)需鍵入首字母%就可以調(diào)用magic函數(shù)。

Some of these commands might come in handy when you're doing everyday tasks in data analysis. Some of them are:

在執(zhí)行數(shù)據(jù)分析的日常任務(wù)時(shí),其中一些命令可能會(huì)派上用場(chǎng)。 他們之中有一些是:

%pastebin (%pastebin)

This function returns the URL and also uploads the code to Pastebin. Pastebin is a content hosting service online where it's possible to store plain text (such as source code snippets) and then share the URL with other people.

此函數(shù)返回URL,并將代碼上傳到Pastebin。 Pastebin是在線的內(nèi)容托管服務(wù),可以存儲(chǔ)純文本(例如源代碼片段),然后與其他人共享URL。

As a matter of fact, a Github gist is very similar to Pastebin, but has version control.

實(shí)際上,Github要點(diǎn)與Pastebin非常相似,但是具有版本控制功能。

%matplotlib筆記本 (%matplotlib notebook)

You can use this inline function for rendering static Matplotlib plots within Jupyter notebooks. You have to try and replace the inline part with a notebook. This will get you resize-able and zoom-able plots quickly.

您可以使用此內(nèi)聯(lián)函數(shù)在Jupyter筆記本中渲染靜態(tài)Matplotlib圖。 您必須嘗試用筆記本替換嵌入式部件。 這將使您能夠快速調(diào)整大小和縮放比例的圖。

But make sure you call the function before you start to import the Matplotlib library.

但是請(qǐng)確保在開(kāi)始導(dǎo)入Matplotlib庫(kù)之前先調(diào)用該函數(shù)。

%跑 (%run)

You can use this function to run a Python script in a notebook.

您可以使用此功能在筆記本中運(yùn)行Python腳本。

%% writefile (%%writefile)

This function writes the cell content into a file. You then write the code into another file named foo.py before saving it into the current directory.

此函數(shù)將單元格內(nèi)容寫(xiě)入文件。 然后,將代碼寫(xiě)入另一個(gè)名為foo.py的文件中,然后再將其保存到當(dāng)前目錄中。

%%膠乳 (%%latex)

This function makes the cell content appear as LaTeX. It comes in handy when writing mathematical equations and formulae in a cell.

此功能使單元格內(nèi)容顯示為L(zhǎng)aTeX。 在單元格中編寫(xiě)數(shù)學(xué)方程式和公式時(shí)非常方便。

查找并刪除錯(cuò)誤 (Find and remove errors)

The function known as the interactive debugger is another magic feature. However, for this article, it has a different category all its own.

稱(chēng)為交互式調(diào)試器的功能是另一個(gè)魔術(shù)功能。 但是,對(duì)于本文,它自己擁有一個(gè)不同的類(lèi)別。

If you are running a code cell and get an exception, type %debug under a new line and then run it. This will open up an environment for interactive debugging that takes you back to the point where the exception happened.

如果您正在運(yùn)行代碼單元并遇到異常,請(qǐng)?jiān)谛滦邢骆I入%debug,然后運(yùn)行它。 這將為交互式調(diào)試打開(kāi)一個(gè)環(huán)境,使您回到發(fā)生異常的地方。

You can also check the values of the different variables that they assigned within the program and, at the same time, perform operations there. After that, if you want to exit the debugger, press q.

您還可以檢查它們?cè)诔绦蛑蟹峙涞牟煌兞康闹?#xff0c;并同時(shí)在其中執(zhí)行操作。 此后,如果要退出調(diào)試器,請(qǐng)按q。

運(yùn)行Python腳本時(shí)使用“ I”選項(xiàng) (Use the ‘I’ option when running Python scripts)

One way to typically run a Python script from the command line is with hello.py. But if you add an -i and run the same Python script, (Python -i hello.py), you get more benefits. How?

通常從命令行運(yùn)行Python腳本的一種方法是hello.py。 但是,如果添加-i并運(yùn)行相同的Python腳本(Python -i hello.py),則會(huì)獲得更多好處。 怎么樣?

First of all, after you get to the program end, Python does not close the interpreter. This means that we can check for the values of the different variables and how correct the functions defined in the program are.

首先,進(jìn)入程序端后 ,Python不會(huì)關(guān)閉解釋器。 這意味著我們可以檢查不同變量的值以及程序中定義的函數(shù)的正確性。

Second, it is then easy to invoke the Python debugger, especially since the interpreter is still available by:

其次,調(diào)用Python調(diào)試器非常容易,特別是因?yàn)榻忉屍魅匀豢梢酝ㄟ^(guò)以下方式使用:

  • Import pdb

    導(dǎo)入pdb
  • Pdb.pm()

    Pdb.pm()

From here, we can quickly get to the point where the exception happened and then work on the code.

從這里,我們可以快速到達(dá)發(fā)生異常的地方,然后對(duì)代碼進(jìn)行處理。

刪除并還原 (Delete and restore)

So what do you do when you mistakenly delete one cell within your Jupyter Notebook? Luckily there is a shortcut for you to undo that action.

那么,當(dāng)您錯(cuò)誤地刪除Jupyter Notebook中的一個(gè)單元格時(shí)該怎么辦? 幸運(yùn)的是,您可以通過(guò)快捷方式撤消該操作。

You can recover or undo your deleted content by hitting CTRL/CMD+Z.

您可以通過(guò)按CTRL / CMD + Z來(lái)恢復(fù)或撤消已刪除的內(nèi)容。

If you have deleted an entire cell that you want to recover, press ESC+Z, or EDIT > Undo Delete Cells.

如果已刪除要恢復(fù)的整個(gè)單元,請(qǐng)按ESC + Z或EDIT> Undo Delete Cells。

結(jié)論 (Conclusion)

This article shared some tips to boost your data analysis skills with Python. These hacks should come in handy for you at some point in your Python data analysis journey.

本文分享了一些技巧,以提高您使用Python的數(shù)據(jù)分析技能。 在您進(jìn)行Python數(shù)據(jù)分析的過(guò)程中,這些技巧應(yīng)該會(huì)很方便。

翻譯自: https://www.freecodecamp.org/news/how-to-boost-your-data-analysis-skills-with-python/

使用python數(shù)據(jù)分析

總結(jié)

以上是生活随笔為你收集整理的使用python数据分析_如何使用Python提升您的数据分析技能的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。