python-datetime

datetime.fromtimestamp vs datetime.utcfromtimestamp, which one is safer to use?

北城以北 提交于 2020-02-26 15:50:44
问题 I'm collecting some data from sensors and I get the timestamp from it like this: "time": { "seconds": 40, "year": 115, "month": 5, "hours": 7, "time": 1434549820776, "date": 17, "minutes": 3, "day": 3, "timezoneOffset": 420 }, I have a python script that processes the data coming from the sensors (incoming data is json format), I take the value of time and converts into readable time format. I used datetime.fromtimestamp(1434549820776/1000).strftime('%Y-%m-%d %H:%M:%S') and that returned

datetime.fromtimestamp vs datetime.utcfromtimestamp, which one is safer to use?

随声附和 提交于 2020-02-26 15:48:33
问题 I'm collecting some data from sensors and I get the timestamp from it like this: "time": { "seconds": 40, "year": 115, "month": 5, "hours": 7, "time": 1434549820776, "date": 17, "minutes": 3, "day": 3, "timezoneOffset": 420 }, I have a python script that processes the data coming from the sensors (incoming data is json format), I take the value of time and converts into readable time format. I used datetime.fromtimestamp(1434549820776/1000).strftime('%Y-%m-%d %H:%M:%S') and that returned

datetime.fromtimestamp vs datetime.utcfromtimestamp, which one is safer to use?

断了今生、忘了曾经 提交于 2020-02-26 15:47:24
问题 I'm collecting some data from sensors and I get the timestamp from it like this: "time": { "seconds": 40, "year": 115, "month": 5, "hours": 7, "time": 1434549820776, "date": 17, "minutes": 3, "day": 3, "timezoneOffset": 420 }, I have a python script that processes the data coming from the sensors (incoming data is json format), I take the value of time and converts into readable time format. I used datetime.fromtimestamp(1434549820776/1000).strftime('%Y-%m-%d %H:%M:%S') and that returned

Derive date column based on different types of values

寵の児 提交于 2020-02-05 06:01:27
问题 I have a dataframe like as shown below df = pd.DataFrame({'subject_id' :[1,2,3,4,5], 'date_of_interview':['2007-05-27','2008-03-13','2010-11-19','2011-10-05','2004-11-02'], 'Age':[31,35,78,72,43], 'value':[6,0.33,1990,np.nan,2001], 'age_detected':[25,35,98,65,40]}) df['date_of_interview'] = pd.to_datetime(df['date_of_interview']) I would like to create a new column called dis_date based on value and age_detected column Ex: subject_id = 1 has date_of_interview as 2007-05-27. If we look at his

Derive date column based on different types of values

雨燕双飞 提交于 2020-02-05 06:01:05
问题 I have a dataframe like as shown below df = pd.DataFrame({'subject_id' :[1,2,3,4,5], 'date_of_interview':['2007-05-27','2008-03-13','2010-11-19','2011-10-05','2004-11-02'], 'Age':[31,35,78,72,43], 'value':[6,0.33,1990,np.nan,2001], 'age_detected':[25,35,98,65,40]}) df['date_of_interview'] = pd.to_datetime(df['date_of_interview']) I would like to create a new column called dis_date based on value and age_detected column Ex: subject_id = 1 has date_of_interview as 2007-05-27. If we look at his

python convert 10 digits datetimestamp to 13 digit GMT timestamp [duplicate]

為{幸葍}努か 提交于 2020-01-24 17:52:44
问题 This question already has answers here : Get current time in milliseconds in Python? (11 answers) Closed 7 days ago . I receive a timestamp from a server like this 1512543958 & when i send back requests in headers i see a 13 digit GMT time stamp like this 1512544485819 By changing the time to local using the code below i get 2017-12-06 12:35:58 print(datetime.datetime.fromtimestamp(int("1512544474")).strftime('%Y-%m-%d %H:%M:%S') & when i apply the code below i get 'Wed 06 Dec 2017 07:14:45

Get day of year from a string date in pandas dataframe

随声附和 提交于 2020-01-22 01:16:29
问题 I want to turn my date string into day of year... I try this code.. import pandas as pd import datetime data = pd.DataFrame() data = pd.read_csv(xFilename, sep=",") and get this DataFrame Index Date Tmin Tmax 0 1950-01-02 -16.508 -2.096 1 1950-01-03 -6.769 0.875 2 1950-01-04 -1.795 8.859 3 1950-01-05 1.995 9.487 4 1950-01-06 -17.738 -9.766 I try this... convert = lambda x: x.DatetimeIndex.dayofyear data['Date'].map(convert) with this error: AttributeError: 'str' object has no attribute

Python: most efficient way to convert date to datetime

三世轮回 提交于 2020-01-21 03:26:25
问题 In Python, I convert a date to datetime by: converting from date to string converting from string to datetime Code: import datetime dt_format="%d%m%Y" my_date = datetime.date.today() datetime.datetime.strptime(my_date.strftime(dt_format), dt_format) I suspect this is far from the most efficient way to do this. What is the most efficient way to convert a date to datetime in Python? 回答1: Use datetime.datetime.combine() with a time object, datetime.time.min represents 00:00 and would match the

Retrieve data from mongodb based on date condition in pymongo

夙愿已清 提交于 2020-01-15 13:21:06
问题 My MongoDB document is as follows: - { "_id" : 111, "ts" : [ ISODate("2010-08-21T23:13:35.000Z"), ISODate("2011-08-23T09:13:10.000Z"), ISODate("2012-08-26T12:55:51.000Z"), ISODate("2010-08-29T03:11:12.000Z") ] } { "_id" : 112, "ts" : [ ISODate("2010-08-21T23:13:35.000Z"), ISODate("2011-08-23T09:13:10.000Z"), ISODate("2012-08-26T12:55:51.000Z"), ISODate("2010-08-29T03:11:12.000Z") ] } Each date entry indicates a "hit". I am trying to count the number of hits each id had between a certain date

Retrieve data from mongodb based on date condition in pymongo

一个人想着一个人 提交于 2020-01-15 13:21:05
问题 My MongoDB document is as follows: - { "_id" : 111, "ts" : [ ISODate("2010-08-21T23:13:35.000Z"), ISODate("2011-08-23T09:13:10.000Z"), ISODate("2012-08-26T12:55:51.000Z"), ISODate("2010-08-29T03:11:12.000Z") ] } { "_id" : 112, "ts" : [ ISODate("2010-08-21T23:13:35.000Z"), ISODate("2011-08-23T09:13:10.000Z"), ISODate("2012-08-26T12:55:51.000Z"), ISODate("2010-08-29T03:11:12.000Z") ] } Each date entry indicates a "hit". I am trying to count the number of hits each id had between a certain date