这就是我的数据框架的样子:
df2.head()
brand brand_len
3 [delta] 1
5 [whirlpool] 1
11 [toro] 1
15 [insinkerator] 1
16 [sunjoy] 1
当我想将字符串Q=['delta','pandas']
与我的df2进行比较时,我没有得到任何匹配。我就是这样做的:
#check for exact similarity
Q = ['delta','pandas']
for q in Q:
print q
for brand in df2.brand:
print brand
if q==brand:
print brand
这是输出:
brand brand_len
3 [delta] 1
5 [whirlpool] 1
11 [toro] 1
15 [insinkerator] 1
16 [sunjoy] 1
delta
[u'delta']
[u'whirlpool']
[u'toro']
[u'insinkerator']
[u'sunjoy']
如何摆脱我的品牌变量中的u。
答案 0 :(得分:1)
你的字符串是Unicode。您可以使用 str(x)函数强制它们成为字符串。
运行以下代码,您将看到会发生什么:
a = u'asd'
print (type(a))
print (type(str(a)))
str(a)