Python Forum
Select specific index for plot - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Select specific index for plot (/thread-14937.html)



Select specific index for plot - rundesquadrat - Dec-25-2018

Hey guys,

I do have here an issue, which I cannot solve alone and thus need your help.

I do have a very large csv table with 27 columns. What I did was to use the multiindex command for "date" and "time", since I do have an object which is observed for several months for a time frame, so you can imagine

Index 1-----Index 2----Attribute

1.1.2018---- 12:00-----0.1
-------------12:01-----0.004
-------------12:03------10



1.2.2018-----13:00-----0.234
-------------13:02-----0.432
-------------13:03-----0.12



.
.
.
.
12.12.2018---11:00-----0.342
-------------11:02-----0.123
-------------11:00-----0.12


So I hope yo guys can imagine the table. So what I did to get a plot was
Data_plot["Attribute"].plot()
If I execute this command I do get the right plot, however the x-axis has the label "Date" and "time", so the multiindex items.

Question: How can I show on the x-axis the date and not the time??

I would be happy for any kind of help


RE: Select specific index for plot - scidam - Dec-26-2018

You probably need to get mean/median values of the attribute per day.

Try this:

your_df.groupby('date_index').mean()['Attribute'].plot()
Also, you can call more general (.transform) method instead of mean:

your_df.groupby('date_index').transform(pd.np.mean)['Attribute'].plot()
# or 
your_df.groupby('date_index').transform(lambda x: your_func(x))['Attribute'].plot()