from datetime import datetime
dt_string = "12/11/2018 09:15:32"
# Considering date is in dd/mm/yyyy format
dt_object1 = datetime.strptime(dt_string, "%d/%m/%Y %H:%M:%S")
print("dt_object1 =", dt_object1)
# Considering date is in mm/dd/yyyy format
dt_object2 = datetime.strptime(dt_string, "%m/%d/%Y %H:%M:%S")
print("dt_object2 =", dt_object2)
# 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.")