Last active
April 5, 2022 15:04
-
-
Save YiLi225/318f0749089e808ad30358f474b7ba07 to your computer and use it in GitHub Desktop.
Query to pull data into Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Query to pull data | |
timeSeries_query = """ | |
SELECT | |
InvoiceDate, | |
Description, | |
ROUND(SUM(Quantity * UnitPrice), 2) AS Total_Sale_Amt | |
FROM | |
OnlineRetail | |
WHERE InvoiceDate BETWEEN '2010-12-01' AND '2011-01-01' | |
AND Description IN ('CHOCOLATE HOT WATER BOTTLE', 'GREY HEART HOT WATER BOTTLE') | |
GROUP BY InvoiceDate, Description | |
ORDER BY InvoiceDate | |
""" | |
## Pull data using pandas | |
df_series = pd.read_sql(timeSeries_query, engine) | |
df_series['InvoiceDate'] = pd.to_datetime(df_series['InvoiceDate']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment