--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
groupby for that:>>> from __future__ import print_function
>>> from __future__ import unicode_literals
>>> import io
>>> import pandas as pd
>>> data = """ndx,V_id,Average,Mean,Peak
... 0,1,3,2,5
... 1,2,2,1,6
... 2,3,4,1,8
... 3,1,2,2,7
... 4,2,3,3,6
... 5,3,5,3,4
... 6,1,1,1,8
... 7,2,2,5,10
... 8,3,5,5,9
... 9,1,2,5,10
... 10,2,5,5,9
... 11,3,4,3,10"""
>>> df = pd.read_csv(io.StringIO(data), index_col=0)
>>> print(df)
V_id Average Mean Peak
ndx
0 1 3 2 5
1 2 2 1 6
2 3 4 1 8
3 1 2 2 7
4 2 3 3 6
5 3 5 3 4
6 1 1 1 8
7 2 2 5 10
8 3 5 5 9
9 1 2 5 10
10 2 5 5 9
11 3 4 3 10
>>> grouper = df.groupby('V_id')
>>> for k in grouper.groups:
... print('\nDataframe-{}'.format(k))
... print(grouper.get_group(k))
...
Dataframe-1
V_id Average Mean Peak
ndx
0 1 3 2 5
3 1 2 2 7
6 1 1 1 8
9 1 2 5 10
Dataframe-2
V_id Average Mean Peak
ndx
1 2 2 1 6
4 2 3 3 6
7 2 2 5 10
10 2 5 5 9
Dataframe-3
V_id Average Mean Peak
ndx
2 3 4 1 8
5 3 5 3 4
8 3 5 5 9
11 3 4 3 10
>>>
groupby for that:
... print(Dataframe-1
(k))
...
Dataframe-1
V_id Average Mean Peak
ndx
0 1 3 2 5
3 1 2 2 7
6 1 1 1 8
9 1 2 5 10
Dataframe-2
V_id Average Mean Peak
ndx
1 2 2 1 6
4 2 3 3 6
7 2 2 5 10
10 2 5 5 9
Dataframe-3
V_id Average Mean Peak
ndx
2 3 4 1 8
5 3 5 3 4
8 3 5 5 9
11 3 4 3 10
>>>
Goyo
Thanks much Goyo,I would like to assign the Dataframe-(k) to the grouper.get_group(k))in the same scriptDo you think is it possible
>>> locals().update((('dataframe_{}'.format(k), grouper.get_group(k))
... for k in grouper.groups))
>>> print(dataframe_1)
V_id Average Mean Peak
ndx
0 1 3 2 5
3 1 2 2 7
6 1 1 1 8
9 1 2 5 10
>>>