-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpm_7_2.py
More file actions
23 lines (18 loc) · 706 Bytes
/
pm_7_2.py
File metadata and controls
23 lines (18 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
pm_7_2.py
use pandas to read sql data from Mysql database using a SELECT query
"""
#library needed to create a connection that pandas can use
from sqlalchemy import create_engine
# pandas
import pandas
#get your connection identifiers
f=open('./identifiers.txt')
mylogin=f.readline().strip('\n')
mypass=f.readline().strip('\n')
# default syntax engine = create_engine('mysql://user:passwd@host/dbname')
engine = create_engine('mysql://%s:%s@localhost/Parcelle' % (mylogin,mypass))
conn = engine.connect()
sql="select year(date) as y, month(date) as m, sum(precip) as pcum from imetos group by month(date),year(date) order by year(date),month(date)"
df = pandas.read_sql(sql,conn)
print(df.head())