我有两张股票报价器。
我创建了SQL联合查询以合并两个表。
query_combined = session\
.query(Table1, Table2)\
.join(Table2, Table1.ticker==Table2.ticker)
然后我将SQL馈送到Pandas以在框架中加载:
df_combined = pandas\
.read_sql(query_combined.statement,
query_combined.session.bind,
index_col='ticker')
但是,由于联接表中有两个“行情指示器”列,因此设置index_col ='ticker'将导致索引列为'(ticker,ticker)'的元组。 我只想将“ ticker”列之一指定为数据帧索引,但不确定如何。
我是熊猫的新手,但我确信这很简单,但是在谷歌搜索的那一刻,我还没有找到答案。在此先感谢您为我指明了正确的方向。
请考虑with_labels
以用下划线with_labels
修饰不明确的列:
<table>_<column>
为了缩短表名称,请在连接之前将表df_combined = (pandas
.read_sql(query_combined.with_labels().statement,
query_combined.session.bind,
index_col='table1_ticker')
)
置于表中:
alias