I simply need to store a month and a date (a birthday) WITHOUT a year value.
When looking at the documentation for pandas (mostly because it has useful time manipulation features), specifically Periods, it states that you need to pass in a timespan and a frequency. I'm not quite sure how to use the frequency part regarding to my problem. What frequency would be most appropriate? Is using pd even the best way to do this?
Thanks!
解决方案
That isn't how Period's work. They represent a specific period in time. Similar to how Timestamp's represent specific points in time.
You seem to want a generic Month-Day label. You can use strftime to get the string but you'll lose any date manipulation.
Consider the series of timestamps with timestamp indices.
s = pd.date_range('2011-01-31', periods=12, freq='M').to_series()
s
2011-01-31 2011-01-31
2011-02-28 2011-02-28
2011-03-31 2011-03-31
2011-04-30 2011-04-30
2011-05-31 2011-05-31
2011-06-30 2011-06-30
2011-07-31 2011-07-31
2011-08-31 2011-08-31
2011-09-30 2011-09-30
2011-10-31 2011-10-31
2011-11-30 2011-11-30
2011-12-31 2011-12-31
Freq: M, dtype: datetime64[ns]
You can get just the month and day like this (see this site for a summary of strftime)
s.dt.strftime('%m-%d')
2011-01-31 01-31
2011-02-28 02-28
2011-03-31 03-31
2011-04-30 04-30
2011-05-31 05-31
2011-06-30 06-30
2011-07-31 07-31
2011-08-31 08-31
2011-09-30 09-30
2011-10-31 10-31
2011-11-30 11-30
2011-12-31 12-31
Freq: M, dtype: object