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

Replacing column strings with numbers in a plot

Is there any way to specify column number as an index to show on x-axis? Consider the following dataframe

      Metric Value Metric Value Metric Value Metric Value
0             3            3            7            7
1             1            1            1            1
2             0            0            0            0

The code below, plots row[0] however, as you can see, "metric Value" is written on the x points. I would like to see 1, 2, 3, 4 instead.

    row = df.iloc[0]
    row.astype(int).plot()
    plt.show()
    

enter image description here

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

>Solution :

Try this:

df.columns = range(1, len(df.columns)+1)
row = df.iloc[0]
row.astype(int).plot()
plt.show()
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