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
Tag: datetime
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
Django model DateTimeField set auto_now_add format or modify the serializer
I have this field in my model: And it is saved with this format: 2016-05-18T15:37:36.993048Z So I would like to convert it to this format DATE_INPUT_FORMATS = (‘%d-%m-%Y %H:%M:S’) but I dont know where to do it. I have a simple serializer class, could I override it to modify the format? or maybe create a get_date() model method? My settings:
Pandas Dataframe datetime slicing with Index vs MultiIndex
With single indexed dataframe I can do the following: Date time slicing works when you give it a complete day (i.e. 2016-01-01), and it also works when you give it a partial date, like just the year and month (2016-01). All this works great, but when you introduce a multiindex, it only works for complete dates. The partial date slicing
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
AttributeError: Can only use .dt accessor with datetimelike values
Hi I am using pandas to convert a column to month. When I read my data they are objects: So I am first making them to date time and then try to make them as months: Also if that helps: So, the error I get is like this: EDITED: Date columns are like this: Do you have any ideas? Thank
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
Pandas: Group by calendar-week, then plot grouped barplots for the real datetime
EDIT I found a quite nice solution and posted it below as an answer. The result will look like this: Some example data you can generate for this problem: resulting in: I’d like to group by calendar-week and by value of col1. Like this: resulting in: Then I want a plot to be generated like this: That means: calendar-week and