:
session.query(Record, RecordMeasurement).filter(Record.record_pkid==RecordMeasurement.record_fkid)
我想构建1个数据框,其中包含Record列的值:
['datetime', 'record_number']
和RecordMeasurement列:
['power', 'voltage', 'temperature']
数据帧列顺序无关紧要。
答案 0 :(得分:3)
将您的查询更改为只包含您需要的列:
query = (session.query(
Record.datetime, Record.record_number,
RecordMeasurement.power, RecordMeasurement.voltage, RecordMeasurement.temperature,
)
.filter(Record.record_pkid==RecordMeasurement.record_fkid)
)
然后致电:
import pandas as pd
# ...
df = pd.read_sql(query.statement, query.session.bind)