import datetime
date_time_str = '2018-06-29 08:15:27.243860'
date_time_obj = datetime.datetime.strptime(date_time_str, '%Y-%m-%d %H:%M:%S.%f')
print('Date:', date_time_obj.date())
print('Time:', date_time_obj.time())
print('Date-time:', date_time_obj)
from datetime import datetime
datetime_str = '09/19/18 13:55:26'
datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')
print(type(datetime_object))
print(datetime_object) # printed in default format
date_str = '09-19-2018'
date_object = datetime.strptime(date_str, '%m-%d-%Y').date()
print(type(date_object))
print(date_object) # printed in default formatting
# app.py
from datetime import datetime
date_str = '10-27-2020'
dto = datetime.strptime(date_str, '%m-%d-%Y').date()
print(type(dto))
print(dto)
>>> import datetime
>>> datetime.datetime.strptime('24052010', "%d%m%Y").date()
datetime.date(2010, 5, 24)
from datetime import datetime
my_date_string = "Mar 11 2011 11:31AM"
datetime_object = datetime.strptime(my_date_string, '%b %d %Y %I:%M%p')
print(type(datetime_object))
print(datetime_object)
# import the datetime module
import datetime
# datetime in string format for may 25 1999
input = '2021/05/25'
# format
format = '%Y/%m/%d'
# convert from string format to datetime format
datetime = datetime.datetime.strptime(input, format)
# get the date from the datetime using date()
# function
print(datetime.date())
Load libraries
import pandas as pd
from datetime import timedelta
# Loading dataset and creating duration column
url = 'https://drive.google.com/uc?id=1YV5bKobzYxVAWyB7VlxNH6dmfP4tHBui'
df = pd.read_csv(url, parse_dates = ['pickup_datetime', 'dropoff_datetime', 'dropoff_calculated'])
df["duration"] = pd.to_timedelta(df["duration"])
# Task 1 - filter to only rides with negative durations
df_neg = df[___["___"] < ___(___)]
# Task 2 - iterate over df_neg rows to find inconsistencies
count = 0
for i, row in df_neg.___():
# Compare minutes of dropoff_datetime and dropoff_calculated
if row["___"].___ != row["___"].minute:
# Print these two columns
print(___[["dropoff_datetime", "dropoff_calculated"]])
# Task 3 - count number of rows having hour greater-equal than 12
if row["___"].___ >= ___:
count ___
print(f"There are {count} rows in df_neg having hour greater-equal than 12.")