亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python - 查找 Twitter 句柄

Python - 查找 Twitter 句柄

墨色風雨 2022-07-12 18:23:19
我是 Python 新手,但試圖從 bios 列表中提取所有 Twitter 句柄?;旧衔倚枰崛?#39;@'之后的內容。示例輸入:['Hello @handle1', '@handle2 @handle3 hello', 'words3', '@handle4']輸出:['handle1', 'handle2', 'handle3', 'handle4']提前致謝!
查看完整描述

2 回答

?
揚帆大魚

TA貢獻1799條經驗 獲得超9個贊

關于您提到的功能,在您使用 a 重構原始數據框后join(),這可能更接近您所追求的:


combined = df[df['variable']!='ref'].set_index('date').join(df[df['variable']=='ref'].set_index('date'), lsuffix='', rsuffix='_ref').drop('variable_ref', axis=1)


def func(series, ref_series):


    #As an example

    return series.mean()/ref_series.mean()


combined.groupby('variable').rolling(12).apply(lambda x: func(x, combined.loc[x.index]['value_ref']), raw=False).drop('value_ref', axis=1)

此示例產生以下結果(NaN由于您的示例數據中存在差距):


                        value

variable date                

item1    2014-01-31       NaN

         2014-02-28       NaN

         2014-03-31       NaN

         2014-04-30       NaN

         2014-05-31       NaN

         2014-06-30       NaN

         2014-07-31       NaN

         2014-08-31       NaN

         2014-09-30       NaN

         2014-10-31       NaN

         2014-11-30       NaN

         2014-12-31       NaN

         2015-01-31       NaN

         2015-02-28       NaN

         2015-03-31       NaN

         2015-04-30       NaN

         2015-05-31       NaN

         2015-06-30       NaN

         2015-07-31       NaN

         2015-08-31       NaN

         2015-09-30  1.912186

         2015-10-31  1.793184

         2015-11-30  2.609254

         2015-12-31  3.009455

         2016-01-31  3.123833

         2016-02-29  2.910599

         2016-03-31  2.708132

         2016-04-30  2.497878

         2016-05-31  2.561760

         2016-06-30  2.681712


查看完整回答
反對 回復 2022-07-12
?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

您可以在沒有正則表達式或導入模塊的情況下執行此操作:


text = ['Hello @handle1', '@handle2 @handle3 hello', 'words3', '@handle4']


handles = [word[1:] for word_group in text for word in word_group.split() if word.startswith('@')]



查看完整回答
反對 回復 2022-07-12
  • 2 回答
  • 0 關注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號