0

I want to show one line graph for each group of data from pandas dataframe.

Dataframe:

tag date value
0 1 20 1
1 1 21 5
2 1 22 3
3 2 20 8
4 2 21 6
5 2 22 14

I tried to execute the below:

for tag_g in df.groupby('tag'):
        tag_g.plot( 'date' , 'value' )

It gives an error:

AttributeError: 'tuple' object has no attribute 'plot'

Notes:

  • Will there be only 2 groups? No, its dynamic. Can have 1 or n number
  • Will there be 3 rows for each group? No, its dynamic. But minimum 3 for sure
koceca
  • 57
  • 6

1 Answers1

0

Your iteration is incorrect. Try this:

for g, frame in df.groupby("tag"):
    frame.plot("date", "value")

See the docs for more on iterating through groups.

not_speshal
  • 22,093
  • 2
  • 15
  • 30
  • ohh, yes. And currently it opens multiple windows for each chart, can there be single window and next previous option two view different charts? – koceca Sep 05 '21 at 18:36
  • That's IDE specific. You'll have to read the relevant docs and settings you need. – not_speshal Sep 05 '21 at 18:42