第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用python循環(huán)遍歷列表并插入str.contains

使用python循環(huán)遍歷列表并插入str.contains

Qyouu 2023-03-01 14:56:32
我的目做每一個(gè)動(dòng)作。DataFramedf有幾列,但我只想將該函數(shù)應(yīng)用于標(biāo)題為“條目”的列,該列包含在線撲克桌上發(fā)生的所有操作的日志(列中的每一行都是一個(gè)字符串)。這是“條目”列的樣子(每行都是一個(gè)字符串):-- ending hand #174 --"Prof @ ZY_G_5ZOve" gained 100"tom_thumb @ g1PBaozt7k" folds"Prof @ ZY_G_5ZOve" calls with 50"tom_thumb @ g1PBaozt7k" checksriver: 9a?|, 5a?£, Qa?¥, 7a?  [Ka? ]"Prof @ ZY_G_5ZOve" checks"tom_thumb @ g1PBaozt7k" checksturn: 9a?|, 5a?£, Qa?¥ [7a? ]"Prof @ ZY_G_5ZOve" checks"tom_thumb @ g1PBaozt7k" checksflop:  [9a?|, 5a?£, Qa?¥]"Prof @ ZY_G_5ZOve" checks"tom_thumb @ g1PBaozt7k" calls with 50"Bob T. @ fjZTXUGV2G" folds"danny G @ tNE1_lEFYv" folds"Prof @ ZY_G_5ZOve" posts a big blind of 50"tom_thumb @ g1PBaozt7k" posts a small blind of 25-- starting hand #174  (Texas Hold'em) (dealer: "Bob T. @ fjZTXUGV2G") ---- ending hand #173 --"tom_thumb @ g1PBaozt7k" gained 475"danny G @ tNE1_lEFYv" folds"Prof @ ZY_G_5ZOve" folds"tom_thumb @ g1PBaozt7k" raises with 356flop:  [4a?¥, Aa? , 6a? ]"danny G @ tNE1_lEFYv" calls with 150"Prof @ ZY_G_5ZOve" calls with 150"tom_thumb @ g1PBaozt7k" raises with 150"Bob T. @ fjZTXUGV2G" folds"danny G @ tNE1_lEFYv" calls with 50"Prof @ ZY_G_5ZOve" calls with 50"tom_thumb @ g1PBaozt7k" posts a big blind of 50"Bob T. @ fjZTXUGV2G" posts a small blind of 25-- starting hand #173  (Texas Hold'em) (dealer: "danny G @ tNE1_lEFYv") --這是我嘗試過的一些示例代碼:player_list = ['danny G', 'Jane', 'Prof', 'spn', 'tim', 'Bob T.', 'joon', 'tom_thumb']action_list = ['call', 'fold']def action_amount(df, player_list, action):    for player in player_list:        action_number =len(df[df['entry'].str.contains('(player).*(action)', regex=True)])        print(f'{player} {action}ed {action_number} times.')action_amount(df, player_list, 'call')值得注意的是,len(df[df['entry'].str.contains('(danny G).*(call)', regex=True)])返回正確的值(我正在使用正則表達(dá)式,因?yàn)槲乙檎业膬蓚€(gè)詞在同一行中,中間有一堆不同的字符)。該問題似乎與嘗試將值循環(huán)到str.contains. 我如何遍歷列表并打印姓名以及該人執(zhí)行給定輸入操作的次數(shù)?理想情況下,我希望同時(shí)遍歷代碼頂部的兩個(gè)列表。
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

這行得通嗎?


def action_amount(df, player_list, action_list):

    for player in player_list:

        for action in action_list:

            pattern = f'{player}.*{action}'

            matching_rows = df[df['entry'].str.contains(pattern, regex=True)]

            action_number = len(matching_rows)

            print(f'{player} {action}ed {action_number} times.')


action_amount(df, player_list, possible_actions)


查看完整回答
反對(duì) 回復(fù) 2023-03-01
  • 1 回答
  • 0 關(guān)注
  • 221 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)