Is it possible to use a dict to group on elements of a column?
For example:
In [3]: df = pd.DataFrame({\'A\' : [\'one\', \'one\', \'two\', \'three\'
From the docs, the dict has to map from labels to group names, so this will work if you put 'A' into the index:
grouped2 = df.set_index('A').groupby(d)
for group_name, data in grouped2:
print group_name
print '---------'
print data
# Output:
End
---------
B
A
three -1.234795
three 0.239209
Start
---------
B
A
one -1.924156
one 0.506046
two -1.681980
two 0.605248
two -0.861364
one 0.800431
Column names and row indices are both labels, whereas before you put 'A' into the index, the elements of 'A' are values.
If you have other info in the index that makes doing a set_index() tricky, you can just create a grouping column with map():
df['group'] = df['A'].map(d)
grouped3 = df.groupby('group')