Be aware that some values could be Unicode strings and may cause the str to throw a UnicodeEncodeError error.
Solution 1:
In that cause replace the str function by the function Unicode.
Example:
Assume the string libie(Dutch for Libya) represented as the Unicode string u’Libi\xeb’ in python.
print str(u ‘Libi\xeb’)
This will throw an error;
Traceback (most recent call last):
File "/Users/tomasz/Python/MA-CIW-Scriptie/RecreateTweets.py", line 21, in <module>
print str(u'Libi\xeb')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xeb' in position 4: ordinal not in range(128)
The following line will throw an error message;
print unicode(u'Libi\xeb') # prints Libië
so replace the line;
values = ','.join([str(i) for i in value_list])
with the following line of code;
values = ','.join([unicode(i) for i in value_list])
This will help to avoid errors.
Solution 2:
Replace the following lines of code;
values = ",".join(value_list)
with the one of the following line;
values = ','.join([str(i) for i in value_list])
OR
values = ','.join(str(value_list)[1:-1])
Solution 3:
The user can also convert the integer data frame into a string first and then do the operations. This can be done by using the following line of code;
df3['nID']=df3['nID'].astype(str)
grp = df3.groupby('userID')['nID'].aggregate(lambda x: '->'.join(tuple(x)))