Background:
I am using pandas to append to an already-existing table in a SQL database. The issue is that the sql database I am connecting to is larger than what pandas can handle. To get around this, I am going to access the table in chunks. The SQL query will contain a WHERE clause, and I want to iterate through it using a list of date ranges.
This is my example SQL query (simplified):
SELECT * FROM (SELECT col1, col2, col3 ... FROM table)
WHERE DATE(server_time) >= min_date AND DATE(server_time) <= max_date
I want to iterate through a list of date ranges to call this query This is how the server_time field is formatted:
'2022-03-29 20:08:57'
So in order to filter the dates, I need to create this list of date ranges, and I am struggling with this.
This is what I tried:
num_months = 3
today = datetime.datetime.today()
date_list = [today - datetime.timedelta(months=x) for x in range(num_months)]
I tried creating a list of date ranges varying by days instead of months, and it worked. I did this by changing (months=x)
to (days=x)
.
When I run the code above, however, I get 'months' is an invalid keyword argument for __new__()
. Any ideas? Thanks so much in advance!!