This should be a relatively simple question.
Below is the sample of my df column:
title2
1 (, 2 ct, , )
2 (, 1 ct, , )
3 (, 2 ct, , )
4 NaN
5 (, 2 ct, , )
6 (, 5 ct, , )
7 (, 7 ounce, , )
8 (, 1 gal, , )
9 NaN
10 NaN
I would like to convert the whole column to a proper string column - i.e. my desired output would be:
title2
1 2ct
2 1ct
3 2ct
4 NaN
5 2ct
6 5ct
7 7 ounce
8 1gal
9 NaN
10 NaN
I have tried the following commands, but none seem to work:
title['title3'] = title['title2'].agg(' '.join)
title['title3'] = title['title2'].apply(lambda x: ''.join(x))
title['title3'] = title['title2'].astype(str)
title['title3'] = title['title2'].values.astype(str)
The answer given in this post: Convert a pandas column containing tuples to string, also does not help me unfortunately.
Can some shed some light on this? Thank you all.
df['title2'].str.join(' ').str.strip()?df['title2'].replace('[(,\s+,)]','',regex=True)