Category : datetime

I can do: df = pd.read_csv(usage_output, parse_dates=[[‘StartDate’, ‘StartTime’],[‘EndDate’, ‘EndTime’]]) I can also do: df = pd.read_csv(usage_output, parse_dates={‘TimeStamp_Start’: [‘StartDate’, ‘StartTime’]}) How to combine both, so that I have two parsed columns "TimeStamp_Start" and "TimeStamp_End"? I tried: df = pd.read_csv(usage_output, parse_dates=[{‘TimeStamp_Start’: [‘StartDate’, ‘StartTime’]}, {‘TimeStamp_End’: [‘EndDate’, ‘EndTime’]}]) Error ValueError: {‘TimeStamp_Start’: [‘StartDate’, ‘StartTime’]} is not in list Source: Python ..

Read more

I’m trying to get number of days between two dates using below function df[‘date’] = pd.to_datetime(df.date) # Creating a function that returns the number of days def calculate_days(date): today = pd.Timestamp(‘today’) return today – date # Apply the function to the column date df[‘days’] = df[‘date’].apply(lambda x: calculate_days(x)) The results looks like this 153 days ..

Read more

I have a GMT datetime: import datetime, pytz d = datetime.datetime(2020, 11, 27, 12, 0, 0) Given a "country+sate" or "country+city" pair (when state is not available) like this: #case 1 country, state = ‘US’, ‘CA’ #case 2 country, city = ‘RU’, ‘Nowosibirsk’ # here no information of "State" is given how to find the ..

Read more

I am trying to convert my string ‘Time’ to Time in Python but getting error Tried multiple things Not Working :- Python datetime formatting without zero-padding Code: dt[‘Time’] = pd.to_datetime(dt[‘Time’], format= ‘%H:%M:%S’, infer_datetime_format=True) Data: Ticker,Date,Time,Open,High,Low,Close,Volume,OpenInterest BANKNIFTY04JUN2023000CE.NFO,14/05/2020,13:00:59,65,65,65,65,20,0 BANKNIFTY04JUN2023000CE.NFO,14/05/2020,15:01:59,75,75,75,75,20,20 BANKNIFTY14MAY2013900PE.NFO,14/05/2020, 9:15:59,0.8,0.8,0.7,0.7,40,18860 Error: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:UsersAnkuranaconda3libsite-packagespandascoretoolsdatetimes.py", line 728, ..

Read more

So I am trying to calculate the duration between two days but I just want the number of days instead of minutes and seconds for the duration. The code I am using is the following: df[‘duration’]=df[‘deadline’].sub(df[‘created_at’].astype(‘datetime64[D]’)) However, this gives me sth like : 35 days 12:42:40. But I don’t want the "days 12:42:40." Instead, I ..

Read more

I am using a for loop to convert all the date in the dataframe to datetime. But since one of the date is in leap year it is giving the error. DeciYear = [] for i in range(0,len(data_ncs)): print(i) d=datetime(data_ncs.Year.iloc[i],data_ncs.Month.iloc[i],data_ncs.Day.iloc[i],data_ncs.Hour.iloc[i], data_ncs.Minute.iloc[i],int(data_ncs.Seconds.iloc[i])) ERROR: ValueError: day is out of range for month The date which is causing ..

Read more

I want to convert this Origin column in the dataframe data_copy to UTC datetime format import pandas as pd >>>data_copy["Origin"] 0 1669-06-04 00:00:00 1 1669-06-22 00:00:00 2 1720-07-15 00:00:00 3 1803-09-01 00:00:00 4 1816-05-26 00:00:00 6395 2020-03-29 18:27:36 6396 2020-03-29 18:47:53 6397 2020-03-29 20:05:19 6398 2020-03-30 02:19:27 6399 2020-03-30 06:11:36 There is also some data ..

Read more