溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

大數(shù)據(jù)處理的3 個(gè)小技巧分別是什么

發(fā)布時(shí)間:2022-01-04 15:39:09 來(lái)源:億速云 閱讀:150 作者:柒染 欄目:大數(shù)據(jù)

今天就跟大家聊聊有關(guān)大數(shù)據(jù)處理的3 個(gè)小技巧分別是什么,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

數(shù)據(jù)處理無(wú)所不在,掌握常用技巧,事半功倍。

此系列使用 Pandas 開(kāi)展數(shù)據(jù)處理分析,總結(jié)其中常用、好用的數(shù)據(jù)分析技巧。

我使用的 Pandas 版本如下,順便也導(dǎo)入 Pandas 庫(kù)。

>>> import pandas as pd
>>> pd.__version__
'0.25.1'
 

今天使用的數(shù)據(jù)集名稱(chēng):IMDB-Movie-Data,取自 Kaggle,百度網(wǎng)盤(pán)下載鏈接如下:

鏈接: https://pan.baidu.com/s/15u7Hf2y5dSFwek2vA1-zjg 提取碼: bvfx

在開(kāi)始前先確保解釋器和數(shù)據(jù)集在同一目錄下:

>>> import os
>>> os.chdir('D://source/dataset') # 這是我的數(shù)據(jù)集所在目錄
>>> os.listdir() # 確認(rèn)此目錄已經(jīng)存在 IMDB-Movie-Data 數(shù)據(jù)集
['drinksbycountry.csv', 'IMDB-Movie-Data.csv', 'movietweetings', 'titanic_eda_data.csv', 'titanic_train_data.csv']
 

準(zhǔn)備工作就位后,正式開(kāi)始數(shù)據(jù)處理技巧之旅。

 
1 Pandas 移除某列

導(dǎo)入數(shù)據(jù)

>>> df = pd.read_csv("IMDB-Movie-Data.csv")
>>> df.head(1) # 導(dǎo)入并顯示第一行
   Rank                    Title                    Genre  ...   Votes Revenue (Millions) Metascore
0     1  Guardians of the Galaxy  Action,Adventure,Sci-Fi  ...  757074             333.13      76.0

[1 rows x 12 columns]
 

使用 pop 方法移除指定列:

>>> meta = df.pop("Title").to_frame() # 移除 Title 列
 

確認(rèn)是否已被移除:

>>> df.head(1) # df 變?yōu)?nbsp;11列
   Rank                    Genre  ... Revenue (Millions) Metascore
0     1  Action,Adventure,Sci-Fi  ...             333.13      76.0

[1 rows x 11 columns]
     
2 統(tǒng)計(jì)標(biāo)題單詞數(shù)

pop 后得到 meta,顯示 meta 前 3 行:

>>> meta.head(3)
                     Title
0  Guardians of the Galaxy
1               Prometheus
2                    Split
 

標(biāo)題是由單詞組成,中間用空格分隔。

# .str.count(" ") + 1 得到單詞個(gè)數(shù) 
>>> meta["words_count"] = meta["Title"].str.count(" ") + 1 
>>> meta.head(3) # words_count 列代表單詞個(gè)數(shù)
                     Title  words_count
0  Guardians of the Galaxy            4
1               Prometheus            1
2                    Split            1
     
3 Genre 頻次統(tǒng)計(jì)

下面統(tǒng)計(jì)電影 Genre 的頻次,

>>> vc = df["Genre"].value_counts()
 

下面顯示電影 Genre 的 Top5 ,最高頻為出現(xiàn) 50 次的 Action,Adventure,Sci-Fi 類(lèi),次之為 48 次的 Drama 類(lèi):

>>> vc.head()
Action,Adventure,Sci-Fi    50
Drama                      48
Comedy,Drama,Romance       35
Comedy                     32
Drama,Romance              31
Name: Genre, dtype: int64
 

展示 Top5 的餅狀圖:

>>> import matplotlib.pyplot as plt
>>> vc[:5].plot(kind='pie')
<matplotlib.axes._subplots.AxesSubplot object at 0x000001D65B114948>
>>> plt.show()
 
大數(shù)據(jù)處理的3 個(gè)小技巧分別是什么  

看完上述內(nèi)容,你們對(duì)大數(shù)據(jù)處理的3 個(gè)小技巧分別是什么有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI