Kaptin Koda
Kaptin Koda

Reputation: 71

How to plot a yearly dataset in python to view trends

I have a dataframe which looks like the table below with 10 records. The columns names are the years. I will like to plot the records so I can visualize the yearly trend of the data with the years as my X axis. How can I achieve this?

+------+------+------+------+
| 2015 | 2016 | 2017 | 2018 |
+------+------+------+------+
|   31 |   25 |   32 |   57 |
|   23 |   54 |   28 |   29 |
|   30 |   25 |   37 |   44 |
|   31 |   25 |   32 |   57 |
+------+------+------+------+

Upvotes: 0

Views: 1179

Answers (2)

Kaptin Koda
Kaptin Koda

Reputation: 71

As suggested by Paul H, df.T.plot() worked

Upvotes: 0

Anıl Ayaydın
Anıl Ayaydın

Reputation: 76

You can use the following code shown as in below:

import pandas as pd
dct = {'2015':['31','23','30','31'],
       '2016':['25'],[54],[25],[25]}
df=pd.DataFrame(dct).melt()
df.plot(x=’Value’, y=’Year’)
plt.show()

If you change the view of graph you can use such as "color", "marker","markersize" parameters.

Upvotes: 1

Related Questions