Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get current group name in a Pandas data frame plot

I have a data frame like that (it’s just the head) :

                       Timestamp Function_code  Node_id  Delta
0     2000-01-01 10:39:51.790683      Tx_PDO_2       54  551.0
1     2000-01-01 10:39:51.791650      Tx_PDO_2       54  601.0
2     2000-01-01 10:39:51.792564      Tx_PDO_3       54  545.0
3     2000-01-01 10:39:51.793511      Tx_PDO_3       54  564.0 

There are only two types of Function_code : Tx_PDO_2 and Tx_PDO_3

I plot in two windows, a graph with Timestamp on the x-axis and Delta on the y-axis. One for Tx_PDO_2 and the other for Tx_PDO_3 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

delta_rx_tx_df.groupby("Function_code").plot(x="Timestamp", y="Delta", )

Now, I want to know which window corresponds to which Function_code

I tried to use title=delta_rx_tx_df.groupby("Function_code").groups but it did not work.

>Solution :

There may be a better way, but for starters, you can assign the titles to the plots after they are created:

plots = delta_rx_tx_df.groupby("Function_code").plot(x="Timestamp", y="Delta")
plots.reset_index()\
     .apply(lambda x: x[0].set_title(x['Function_code']), axis=1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading