Skip to content

Instantly share code, notes, and snippets.

@kdeenanauth
Last active July 26, 2017 21:22
Show Gist options
  • Save kdeenanauth/dc07201f9c0ff96d4f40d4e16497d66a to your computer and use it in GitHub Desktop.
Save kdeenanauth/dc07201f9c0ff96d4f40d4e16497d66a to your computer and use it in GitHub Desktop.
Concat
>>> data = [{'col1': 'a', 'col2': 'z'}, {'col1':'b', 'col2': 'z'}, {'col1':'c', 'col2':'y'}, {'col1':'d', 'col2':'y'}]
>>> data
[{'col1': 'a', 'col2': 'z'}, {'col1': 'b', 'col2': 'z'}, {'col1': 'c', 'col2': 'y'}, {'col1': 'd', 'col2': 'y'}]
>>> df = pandas.DataFrame(data)
>>> df.groupby('col2')['col1'].apply(lambda x : x.str.cat(sep=', '))
col2
y c, d
z a, b
Name: col1, dtype: object
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment