【发布时间】:2019-02-25 11:12:17
【问题描述】:
我的 pandas 数据框中有以下列 - client_1_name、client_2_name、clinet_3_name...一直到 client_10_name。
我想使用列名中的数字遍历列名,以确定特定列是否包含子字符串 - “Nike”。
我将如何理想地解决问题:
for i in range(1,10):
df['Nike'] = df['Client_'+i+'_name'].str.contains('Nike', regex = True)
但我收到以下错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-85-28926af604a8> in <module>()
2
3 for i in range(1,10):
----> 4 df_nike['Nike'] = df_nike['client_'+i+'_name'].str.contains('Nike', regex = True)
TypeError: can only concatenate str (not "int") to str
关于如何做到这一点的建议?
【问题讨论】:
标签: python regex string pandas