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

How to plot a line graph of an array from a dataframe?

I have a dataframe, test, that contains winter temperatures since 1951 for a city. I want to plot the temperatures contained in the column called p95_annual but when I try to do that using plt.plot(test.p95_annual.values) I get the following:
enter image description here
Here’s what test, wintermean, and test.wintermean.values looks like:
enter image description here
How can I plot this temperature data?

>Solution :

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

You have one single row in your DataFrame which has a string. You need to parse the individual values from this string before plotting it:

data = list(map(int, test.at[124,"p95_annual"][1:-1].split()))

>>> plt.plot(data)

enter image description here

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