首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >运行numpy select时的TypeError

运行numpy select时的TypeError
EN

Stack Overflow用户
提问于 2019-08-03 20:15:45
回答 1查看 33关注 0票数 0

我正在尝试运行代码,通过luigi包匹配url中的特定字符串值,同时接收csv并返回多个csv。

代码:

代码语言:javascript
运行
复制
class wrapper(luigi.WrapperTask):
        file = '/Users/emmanuels/Desktop/cleanattribution.csv'
        conditions  = [(file["properties_path"].str.contains('blog|article|page/2|page/3|pulse-2019') ==  True)|
                       (file["context_page_title"].str.contains('blog|Blog') == True),
                       (file["properties_path"].str.contains('credit|index.html|announce|translate_url|search|welcome|card-machines|static|point-of-sale-app|team|transaction|y-store|store|about|yoco-tap|faq|control|integrations|connect-reader|fitness|accessories|v3|vend|top-5|press|stories|xero|where-to-buy|tabletp|info|reseller|retail|v2|card|affiliates|vwo|small-business-profile|translate_c') == True)|
                       (file["properties_path"] == '/i')|
                       (file["properties_url"] == 'https://www.yoco.co.za/za/'),
                       file["properties_path"].str.contains('signup|sign-up|create-account|continue|checkout|merchant-agreement|restart|terms|pickup|pick-up') == True,
                       file["properties_path"].str.contains('complete') == True,
                       (file["properties_path"] == '/da/') | 
                       (file['properties_path'] == '/') | 
                       (file['properties_path'].str.contains('hair') == True)|
                       (file['properties_path'] == '/da'),
                       file["properties_path"].str.contains('promo|iHeartMarket|BrownSense|growth-awards|SolBeerSouthAfrica|2ov|festival-of-beer|Pretoria|tourism|payday||brownsense|iheartmarket|plan-my-wedding|hello-pretty|readyforseason|matchmakers|priceless|optimizely|awethu|flash-sale|2017|pretoriaeast|digi') == True,
                       file["properties_path"].str.contains('capital') == True,
                       (file["properties_path"].str.contains('justst|just|Just-Start|growth') == True)|
                       (file["context_page_title"].str.contains('Just Start') == True),
                       file["properties_path"].str.contains('careers')== True,
                       (file["properties_path"].str.contains('contact|call-me-back|demos|demo') == True)|
                       (file["context_page_title"].str.contains('Contact')==True),
                       (file["context_page_title"].str.contains('portal') == True)|
                       (file["properties_url"].str.contains('portal') == True)|
                       (file["properties_path"].str.contains('portal|history|email-notifications|point-of-sale|invoices|account|settlements|hardware|products|lets-grow|reports|business/details') == True),
                       file["properties_path"].str.contains('for-the-sales|forthe') == True,
                       file["properties_path"].str.contains('developers|sdk') == True,
                       (file["context_page_title"] == 'Not Found')|
                       (file["properties_path"].str.contains('404|page-data.json|not-found') == True)|
                       (file["context_page_title"] == 'Page not found')|
                       (file["properties_path"].str.contains('Get%20Yo') == True),
                       file["properties_path"].str.contains('abtasty') == True,
                       file["properties_path"].str.contains('401') == True,
                       file["properties_path"].str.contains('df') == True,
                       (file["context_page_title"].str.contains('Testing|Generating preview|moove_landing') == True)|
                       (file["properties_path"].str.contains('moove_landing') == True),
                       (file["properties_path"].str.contains('Users|storage|blank|conversion-test|temp|jiuze|api/v1|object%20|NaN|EMBROIDERY') == True)|
                       file["properties_search"].str.contains('elementor-preview') == True]
        choices = [ "blog","info_pages","signup","completed","home_page","promo_pages","ds-capital","just-start","careers_page","contact","portal","for_the_sales","developers","404","abtasty","401-protected page","Yogoals","Testing","Other"]
        file["page_type"] = np.select(conditions, choices, default=np.nan)
        actions = list(set(file["page_type"]))
        def requires(self):
                task_list = []
                for current_task in actions:
                        task_list = task_list.append(data_filter(task=current_task))
                return task_list
        def run(self):
                print ('Wrapper has ended')
                pd.DataFrame().to_csv('/Users/emmanuels/Documents/GitHub/datawranglerwrapper.csv') #will continue running if we don't add this here- we know everything before has been run
        def output(self):
                return luigi.LocalTarget('/Users/emmanuels/Documents/GitHub/datawranglerwrapper.csv') #indicator of success, if successful won't run again
if __name__ == '__main__':
    luigi.run(wrapper(workers=2))

问题是,当我在终端上运行我的代码时,我一直遇到这个错误消息:

代码语言:javascript
运行
复制
  File "cleancopy.py", line 19, in wrapper
    conditions  = [(file["properties_path"].str.contains('blog|article|page/2|page/3|pulse-2019') ==  True)|
TypeError: string indices must be integers
EN

回答 1

Stack Overflow用户

发布于 2019-08-03 21:18:55

“‘file”是字符串类型。使用整数值作为索引,而不是变量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57338220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档