The u
indicates that it is a unicode string, which is a way to encode strings that supports letters of any alphabet, as opposed to the ascii that only supports those of the English alphabet.
What is happening to you is that you are directly printing a variable of type "set", which is the result of the operation. Python is very flexible when it comes to allowing you to show any variable on the screen, since it always tries to convert these variables to a format that can be seen and understood in the output. In this case what it does is show the same syntax with which you could re-create the result set from a list. That is, it shows set()
and within the parentheses and between brackets, all the elements of the set separated by commas. Since each element in this case is a Unicode string, it shows it to you with the syntax in which you would have to write it in a python program, that is, u'contenido'
.
If you simply want the content, without quotes, without u
and without commas, you should not try to show the whole set directly, but iterate over it and show yourself each item one by one. For example:
resultado = set(df['col1']).intersection(set(df['col2']))
for elemento in resultado:
print(elemento)
In this case, every elemento
that you pass to print()
is a Unicode string, but print()
knows how to display these strings without resorting to its "python representation" as it did in the case of the set. You will see them "normal", without quotes or u
.
You can also use join()
to convert the result set to a string that is separated by commas (or by the separator you prefer) the elements. So:
cadena = ", ".join(resultado)
In your case the cadena
would contain at the end:
'MCM7, GNG11, PON2, RARRES2, HSPB1, GRM3, PTPRZ1, RHEB, PTN, MEST, PEG10, TSC22D4'