1

For a given dataframe with a datetime column (2018-09-09 06:15:00), I would like to find all the rows that match a given date "2018-01-08".

I have tried something like this:

def get_connections(df, mydate):
    connections = df.loc[(df['dates']) == mydate]
    return connections

2 Answers 2

2

Here is a solution,

import pandas as pd

df = pd.DataFrame({"dates":["2018-09-09 06:15:00", "2018-01-08 06:15:00"]})

df[pd.to_datetime(df.dates).dt.strftime("%Y-%m-%d").eq("2018-01-08")]

                 dates
1  2018-01-08 06:15:00
Sign up to request clarification or add additional context in comments.

Comments

1

try this

from datetime as datetime as dt
df['dates'] = df['dates'].apply(dt.fromisoformat)

def get_connections(df, mydate):
    connections = df.loc[df['dates'].apply(dt.date) == dt.strptime(mydate, '%Y-%m-%d')]
    return connections
get_connections(datestring)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.