1

I have this data frame, where id is an int64, and date is datetime64[ns]:

         id                        date
0   1811302  2017-03-08 00:00:00.000000
1     16095  2013-03-12 00:00:00.000000
2     16095  2017-09-15 00:00:00.000000
..      ...                         ...
74  1111806  2017-09-15 00:00:00.000000
75   482254  2013-01-01 00:00:00.000000
76   482254  2015-12-16 00:00:00.000000

In reality, my data frame has more than a million number of rows.

Now, using pandasql, how do I extract rows before a given date, say before 2017-09-11?

I tried:

sqlcode = 'SELECT id, date from df where strftime("%Y-%m-%d", date) < {}'.format("2017-09-11")
ps.sqldf(sqlcode,locals())

Which returns nothing:

Empty DataFrame
Columns: [id, date]
Index: []

Any suggestions?

1 Answer 1

1

Okay, it turns out the quotes around the curly brackets are important:

sqlcode = 'SELECT id, date from df where strftime("%Y-%m-%d", date) < "{}"'.format("2017-09-11")
ps.sqldf(sqlcode,locals())
Sign up to request clarification or add additional context in comments.

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.