I have a simple dataset:
I want to compress the feature text column in ',' by animal, so my output will look like:
I appreciate any ideas on it. Thank you
I have a simple dataset:
I want to compress the feature text column in ',' by animal, so my output will look like:
I appreciate any ideas on it. Thank you
You can use a groupby:
>>> df.groupby('animal')['Feature'].apply(','.join)
animal
bird B,C
cat A,C
Name: Feature, dtype: object
Note: for reproducible setup (preferred to an image):
df = pd.DataFrame({
'animal': ['cat', 'cat', 'bird', 'bird'],
'Feature': list('ACBC'),
})