Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Last active April 5, 2022 15:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save YiLi225/318f0749089e808ad30358f474b7ba07 to your computer and use it in GitHub Desktop.
Save YiLi225/318f0749089e808ad30358f474b7ba07 to your computer and use it in GitHub Desktop.
Query to pull data into Python
## 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