jmbejara / comp-econ-sp19

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2019)
48 stars 26 forks source link

HW 3 Productivity: Plotting a df with multi-index #30

Closed henryli78 closed 5 years ago

henryli78 commented 5 years ago

Hi! I'm trying to do Q3-Q5 on HW3's productivity section. I'm right now doing something that I feel is inefficient, i.e.:

df['y'].loc[0].plot() df['y'].loc[1].plot() df['y'].loc[2].plot()

but my issue is that this seems really inefficient. Is there some better way of doing this? I tried to read through the help for the df.plot() function here but it didn't seem to help me too much.

Thanks!

jmbejara commented 5 years ago

You can just use matplotlib.pyplot and give it multiple rows. I did it like this:

image

jmbejara commented 5 years ago

Another option is to use a "for-loop." Yet another option, using the DataFrame, is this:

df['y'].unstack().T.plot()

image

henryli78 commented 5 years ago

Thank you! This works very well.