I was trying to convert the below tags column to normal string without the brackets and commas and tried the below two ways but I’m getting error.
can someone tell a correct way
Error: can only join an iterable
>Solution :
If there are missing values and lists filled by strings, you can use Series.str.join:
new['tags'] = new['tags'].str.join(' ')
Or join only rows with no missing values:
m = new['tags'].notna()
new.loc[m, 'tags'] = new.loc[m, 'tags'].apply(' '.join)
If there are also non strings values in lists:
new = pd.DataFrame({'tags': [['In','ss',5], None]})
m = new['tags'].notna()
new.loc[m, 'tags'] = new.loc[m, 'tags'].apply(lambda x : ' '.join(map(str, x)))
print (new)
tags
0 In, ss, 5
1 None
