Checking whether the given Date is missing from the data frame

Here we are returning True if the date is present and False if the date is missing from the data frame.

Python3




import pandas as pd
# A dataframe from a dictionary of lists
data = {'Date': ['2021-01-18', '2021-01-20',
                 '2021-01-23', '2021-01-25'],
       'Name': ['Jia', 'Tanya', 'Rohan', 'Sam']}
 
df = pd.DataFrame(data)
 
df['Date'] = pd.to_datetime(df['Date'])
 
d='2021-01-19'
print(pd.to_datetime(d) in df['Date'].tolist())


Output:

True

Check missing dates in Pandas

In this article, we will learn how to check missing dates in Pandas.

A data frame is created from a dictionary of lists using pd.DataFrame() which accepts the data as its parameter. Note that here, the dictionary consists of two lists named Date and Name. Both of them are of the same length and some dates are missing from the given sequence of dates ( From  2021-01-18 to 2021-01-25 ).

Check missing dates

Similar Reads

Checking whether the given Date is missing from the data frame

Here we are returning True if the date is present and False if the date is missing from the data frame....

Using data_range() and .difference() function to check missing dates

...

Using reindex() function to check missing dates

Example 1:...