conn_rest_pandas.py 790 字节
Newer Older
1
import pandas
S
sunpeng 已提交
2
from sqlalchemy import create_engine, text
3 4

engine = create_engine("taosrest://root:taosdata@localhost:6041")
S
sunpeng 已提交
5 6 7
conn = engine.connect()
df: pandas.DataFrame = pandas.read_sql(text("SELECT * FROM power.meters"), conn)
conn.close()
8 9 10 11 12 13 14 15 16

# print index
print(df.index)
# print data type  of element in ts column
print(type(df.ts[0]))
print(df.head(3))

# output:
# RangeIndex(start=0, stop=8, step=1)
17 18 19 20 21
# <class 'pandas._libs.tslibs.timestamps.Timestamp'>
#                                 ts  current  ...               location  groupid
# 0 2018-10-03 06:38:05.500000+00:00     11.8  ...  california.losangeles        2
# 1 2018-10-03 06:38:16.600000+00:00     13.4  ...  california.losangeles        2
# 2        2018-10-03 06:38:05+00:00     10.8  ...  california.losangeles        3