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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

统计123出现次数_如何使用 count 统计词条出现次数?

發布時間:2025/3/21 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 统计123出现次数_如何使用 count 统计词条出现次数? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  如何獲取數據最多的3個分類?如何使用count統計詞條出現次數?今天番茄加速跟大家講一下。

  如何快速拿到數據最多的 3 個分類?

  讀入數據:

  df = pd.read_csv("IMDB-Movie-Data.csv")

  df

  1000 行數據,genre 取值的頻次統計如下:

  vc = df["genre"].value_counts()

  vc

  打印結果:

  Action,Adventure,Sci-Fi 50

  Drama 48

  Comedy,Drama,Romance 35

  Comedy 32

  Drama,Romance 31

  ..

  Adventure,Comedy,Fantasy 1

  Biography,History,Thriller 1

  Action,Horror 1

  Mystery,Thriller,Western 1

  Animation,Fantasy 1

  Name: genre, Length: 207, dtype: int64

  篩選出 top3 的 index:

  top_genre = vc[0:3].index

  print(top_genre)

  打印結果:

  Index(['Action,Adventure,Sci-Fi', 'Drama',

  'Comedy,Drama,Romance'], dtype='object')

  使用得到的 top3 的 index ,結合 isin,選擇出相應的 df

  df_top = df[df["genre"].isin(top_genre)]

  df_top

  結果:

  如何使用 count 統計詞條出現次數?

  讀入 IMDB-Movie-Data 數據集,1000行數據:

  df = pd.read_csv("../input/imdb-data/IMDB-Movie-Data.csv")

  df['Title']

  打印 Title 列:

  0 Guardians of the Galaxy

  1 Prometheus

  2 Split

  3 Sing

  4 Suicide Squad

  ...

  995 Secret in Their Eyes

  996 Hostel: Part II

  997 Step Up 2: The Streets

  998 Search Party

  999 Nine Lives

  Name: Title, Length: 1000, dtype: object

  標題是由幾個單詞組成,用空格分隔。

  df["words_count"] = df["Title"].str.count(" ") + 1

  df[["Title","words_count"]]

總結

以上是生活随笔為你收集整理的统计123出现次数_如何使用 count 统计词条出现次数?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。