亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python中pandas的dataframe過(guò)濾數(shù)據(jù)方法

 更新時(shí)間:2023年07月06日 09:08:19   作者:菜鳥(niǎo)小超  
這篇文章主要介紹了Python中pandas的dataframe過(guò)濾數(shù)據(jù)方法,Pandas是另外一個(gè)用于處理高級(jí)數(shù)據(jù)結(jié)構(gòu)和數(shù)據(jù)分析的Python庫(kù),Pandas是基于Numpy構(gòu)建的一種工具,需要的朋友可以參考下

  • 選取某一列中大于某個(gè)值的行:
df[df['column_name'] > value]
  • 選取某一列中滿足多個(gè)條件的行:
df[(df['column_name'] > value1) & (df['column_name'] < value2)]
  • 選取某一列中不等于某個(gè)值的行:
df[df['column_name'] != value]
  • 選取某一列中包含某個(gè)字符串的行:
df[df['column_name'].str.contains('string')]
  • 選取多個(gè)列中滿足某個(gè)條件的行:
df[(df['column_name1'] > value1) & (df['column_name2'] < value2)]

在以上例子中,df是pandas DataFrame對(duì)象,‘column_name’、‘column_name1’、'column_name2’是DataFrame的列名,value、value1、value2是篩選條件。通過(guò)這些布爾索引的使用,可以方便地選取滿足特定條件的行。

演示demo

假設(shè)有一個(gè)包含電影信息的數(shù)據(jù)集,包含電影名稱、導(dǎo)演、評(píng)分等信息。數(shù)據(jù)集如下:

電影名稱導(dǎo)演評(píng)分
TitanicJames Cameron7.8
AvatarJames Cameron8.5
The Shawshank RedemptionFrank Darabont9.3
The GodfatherFrancis Ford Coppola9.2
The Dark KnightChristopher Nolan9.0
InceptionChristopher Nolan8.8

下面是使用布爾索引過(guò)濾數(shù)據(jù)的例子:

輸出結(jié)果如下:

             電影名稱                    導(dǎo)演   評(píng)分
0         Titanic          James Cameron  7.8
1          Avatar          James Cameron  8.5
2  The Shawshank Redemption    Frank Darabont  9.3
3    The Godfather  Francis Ford Coppola  9.2
4  The Dark Knight     Christopher Nolan  9.0
5        Inception     Christopher Nolan  8.8

              電影名稱                 導(dǎo)演   評(píng)分
4   The Dark Knight  Christopher Nolan  9.0
5         Inception  Christopher Nolan  8.8

                   電影名稱                 導(dǎo)演   評(píng)分
2  The Shawshank Redemption    Frank Darabont  9.3

在以上例子中,第一個(gè)過(guò)濾條件是選取評(píng)分大于8.0的電影,第二個(gè)過(guò)濾條件是選取由Christopher Nolan執(zhí)導(dǎo)的電影,第三個(gè)過(guò)濾條件是選取電影名稱中包含"Redemption"的電影。根據(jù)這些過(guò)濾條件,我們可以得到不同的結(jié)果。

到此這篇關(guān)于Python中pandas的dataframe過(guò)濾數(shù)據(jù)方法的文章就介紹到這了,更多相關(guān)pandas的dataframe過(guò)濾數(shù)據(jù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論