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

Is there a way to plot two columns of a data frame in the same axis?

I have a dataframe which consists of 3 colums: ‘Date’, ‘Time’ and ‘Data’
I want to plot ‘Date’ and ‘Time’ and the X axis and ‘Data’ on the Y axis. So far, since I used pandas to import my data set, I tried with:

df.plot(x= "Date", y="Data")

but I think it only allows one argument in ‘x=’

I also wonder if in this case, is better to define ‘Date’ and ‘Time’ as a single column

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

Thank you for your support!

>Solution :

You can create a new column called "DateTime" that combines "Date" and "Time".

Then plot it on the x axis and "Data" on the y axis:

import pandas as pd

df = ...

df["DateTime"] = pd.to_datetime(df['Date'].astype(str) + df['Time'].astype(str), format="%m-%d-%Y%H:%M:%S")
df.plot(x="DateTime", y="Data")
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