MAS
MAS

Reputation: 4993

comparing a string with a panda dataframe

This is how my dataframe looks like:

df2.head()
             brand  brand_len
3   [delta]         1        
5   [whirlpool]     1        
11  [toro]          1        
15  [insinkerator]  1        
16  [sunjoy]        1     

When I want to compare a string Q=['delta','pandas'] with my df2, I don't get any match. This is how I am doing it:

#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

This is the output:

             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']

How can I get rid of the u presented in my brand variable.

Upvotes: 0

Views: 1120

Answers (1)

lps
lps

Reputation: 144

Your Strings are Unicode. You can force them to be strings by using str(x) function.

Run the following code and you will see what happens:

a = u'asd'
print (type(a))
print (type(str(a)))
str(a)

Upvotes: 1

Related Questions