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?

  • Does this answer your question? [Convert Pandas Column to DateTime](https://stackoverflow.com/questions/26763344/convert-pandas-column-to-datetime) – BenT Apr 06 '20 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 – ricksterrocket Apr 06 '20 at 22:19

1 Answers1

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')
BenT
  • 3,172
  • 3
  • 18
  • 38