2

I have 2 pandas series data for days in a year that I want to graph on the same axis.

series 1:

 date    value
01-01    15.6
01-02    13.9
01-03    13.3
...
12-28    19.4
12-29    12.8
12-30    11.7
12-31    11.9


series 2:

 date     value
02-09     8.3
04-17    27.8
05-07    30.6
05-08    33.3
...
12-23    18.3
12-24    17.2
12-25    11.1

one series has observations from every day in a year and the other only has observations from select days in the year.

Currently dates index is just a string, not a datetime value. The year is irrelevant to the data but its fine to set an abitrary one to convert the data if necessary (like 2015).

How would I achieve this? Is there a way to convert both series to datetime somehow?

2
  • Does this answer your question? Convert Pandas Column to DateTime Commented Apr 6, 2020 at 21:46
  • possibly, but as you can see my dates are formatted (month-day) with no year value specified, so converting to datetime throws an error Commented Apr 6, 2020 at 22:19

1 Answer 1

1

If you are having issues converting to a Datetime object then you just need to add an arbitrary year in there.

df['date'] = pd.to_datetime('2018 '+df.date.astype(str) ,format='%Y %m-%d')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.