Last active
July 26, 2017 21:22
-
-
Save kdeenanauth/dc07201f9c0ff96d4f40d4e16497d66a to your computer and use it in GitHub Desktop.
Concat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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