Skip to content
Advertisement

Tag: datetime

Python: Datetime to season

I want to convert a date time series to season, for example for months 3, 4, 5 I want to replace them with 2 (spring); for months 6, 7, 8 I want to replace them with 3 (summer) etc. So, I have this series and this is the code I have been trying to use, but to no avail. and

Converting to unix timestamp Python

I am trying to convert a datestamp of now into Unix TimeStamp, however the code below seems to be hit but then just jumps to the end of my app, as in seems to not like the time.mktime part. Answer Change newDate = time.mktime(datetime.strptime(toDayDate, “%Y-%m-%d %H:%M:%S”).timetuple()) to newDate = time.mktime(datetime.timetuple()) as an example I did: and got unix_secs = 1488214742.0

How to filter a pandas series with a datetime index on the quarter and year

I have a Series, called ‘scores’, with a datetime index. I wish to subset it by quarter and year pseudocode: series.loc[‘q2 of 2013’] Attempts so far: s.dt.quarter AttributeError: Can only use .dt accessor with datetimelike values s.index.dt.quarter AttributeError: ‘DatetimeIndex’ object has no attribute ‘dt’ This works (inspired by this answer), but I can’t believe it is the right way to

How to convert datetime object to milliseconds

I am parsing datetime values as follows: How can I convert this datetime objects to milliseconds? I didn’t see mention of milliseconds in the doc of to_datetime. Update (Based on feedback): This is the current version of the code that provides error TypeError: Cannot convert input to Timestamp. The column Date3 must contain milliseconds (as a numeric equivalent of a

Pandas: Assign Datetime object to time intervals

I’m trying to create a new variable in which datetime64[ns] objects are assigned to 5 minute intervals. The new interval variable should span every 5 minute period from 00:00 to 23:55. The criteria for assignment is whether the time of the datetime64[ns] object falls within the corresponding 5 min interval. My actual data has numerous dates in the DateTime variable,

Python: Matplotlib avoid plotting gaps

I am currently generating the plot below: with this code: where intra.to_pydatetime() is a: <bound method DatetimeIndex.to_pydatetime of <class ‘pandas.tseries.index.DatetimeIndex’> [2011-01-03 09:35:00, …, 2011-01-07 16:00:00] Length: 390, Freq: None, Timezone: None> So the dates go from 2011-01-03 09:35:00, increments by 5 minutes until 16:00:00, and then jumps to the next day, 2011-01-04 09:35:00 until 2011-01-04 16:00:00, and so on. How

Advertisement