我在查詢我的SQLAlchemy映射的星型模式,直接進入pandas DataFrame
,並從pandas
得到一個討厭的SAWarning,我想解決這個問題。這是一個簡化版本。將SQLAlchemy查詢爲熊貓時SAWarning df
class School(Base):
__tablename__ = 'DimSchool'
id = Column('SchoolKey', Integer, primary_key=True)
name = Column('SchoolName', String)
district = Column('SchoolDistrict', String)
class StudentScore(Base):
__tablename__ = 'FactStudentScore'
StudentKey = Column('StudentKey', Integer, ForeignKey('DimStudent.StudentKey'), primary_key = True)
SchoolKey = Column('SchoolKey', Integer, ForeignKey('DimSchool.SchoolKey'), primary_key = True)
PointsPossible = Column('PointsPossible', Integer)
PointsReceived = Column('PointsReceived', Integer)
student = relationship("Student", backref='studentscore')
school = relationship("School", backref='studentscore')
我查詢的日期與聲明是這樣的:
standard = session.query(StudentdScore, School).\
join(School).filter(School.name.like('%Dever%'))
testdf = pd.read_sql(sch.statement, sch.session.bind)
再得到這樣的警告:
SAWarning: Column 'SchoolKey' on table <sqlalchemy.sql.selectable.Select at 0x1ab7abe0; Select object> being replaced by Column('SchoolKey', Integer(), table=<Select object>, primary_key=True, nullable=False), which has the same key. Consider use_labels for select() statements.
我得到這個錯誤,每增加表(類)包含在我加入。該消息始終引用外鍵。
其他人遇到此錯誤並確定根本原因?或者你會忽略它嗎?
編輯/ UPDATE:
Handling Duplicate Columns in Pandas DataFrame constructor from SQLAlchemy Join
這些傢伙似乎是在談論一個相關的問題,但它們使用不同的熊貓方法,使數據幀中,並希望保持重複,而不是刪除它們。任何人都有關於如何實現類似樣式函數的想法,但在查詢返回時刪除重複項?