0

I am attempting to isolate the rows in a dataframe where dates match a user inputted date. Here is the full code with an included dataframe. Why doesn't it return my row?

import pandas as pd
from datetime import datetime
df = pd.DataFrame({"Day": pd.to_datetime("2022-10-26"), "y": 5}, index=[0])
print(df)

get_year = input("Enter Year: ")
get_month = input("Enter Month: ")
get_day= input("Enter Day of Month: ")

inputdate = get_year+"-"+get_month+"-"+get_day
rundate1 = datetime.strptime(inputdate,'%Y-%m-%d')
rundate = (rundate1.date())
print(rundate)
x = df[df['Day']] == rundate
print(x)

1 Answers1

0

in Series checks the index, you can do in Series.tolist() or Series.eq().any()

rundate = pd.to_datetime(inputdate)

if rundate in df["Day"].tolist():
    print("yes its in here")
# or
if df["Day"].eq(rundate).any():
    print("yes its in here")
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52