title: Imperative mapping of a pandas DataFrame to a single table row in SQLAlchemy
body: <p>I have an class which I am trying to map using <a href="https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#imperative-a-k-a-classical-mappings" rel="nofollow noreferrer">imperative mapping with SQLAlchemy</a>.</p>
  <p>One of the attributes of this class when it is instanced is a pandas DataFrame such that</p>
  <pre><code>class ClassToBeMapped:
      def __init__(self, name: str, data_table: pandas.DataFrame):
          self.name = name
          self.data_table = data_table
  </code></pre>
  <p>where <code>data_table</code> is of structure</p>
  <pre><code>   foo  bar
  0  0.1  0.2
  1  4.0  5.0
  2  0.7  0.8
  </code></pre>
  <p>In the ORM, I have so far defined the SQLAlchemy Table for ClassToBeMapped as</p>
  <pre><code>Table(
      'mapped_classes',
      metadata,
      Column('id', Integer, primary_key=True, autoincrement=True),
      Column('name', String(255))
  )
  </code></pre>
  <p>I would like to map another Table which stores the 2D DataFrame <code>data_table</code> as a single row in the database such that</p>
  <pre><code>Table(
      'data_tables',
      metadata,
      Column('id', Integer, primary_key=True, autoincrement=True),
      Column('assoc_name', String(255), ForeignKey('mapped_clases.name')),
      Column('foo_0', Float),
      Column('foo_1', Float),
      Column('foo_2', Float),
      Column('bar_0', Float),
      Column('bar_1', Float),
      Column('bar_2', Float)
  )
  </code></pre>
  <p>How would I correctly declared a SQLAlchemy Table so that when I map <code>data_table</code> to it using <a href="https://docs.sqlalchemy.org/en/14/orm/mapping_api.html#sqlalchemy.orm.registry.map_imperatively" rel="nofollow noreferrer"><code>map_imperatively</code></a>, SQLAlchemy knows that each of the columns in the SQLAlchemy Table refer to a single value from a location in the database? (e.g. <code>Column('foo_0', Float)</code> corresponds to <code>data_table.loc[0, 'foo']</code>)</p>
  <p>Note: pandas.DataFrame.to_sql is not appropriate here as the 2D DataFrame contains data associated with a single object, not multiple separate rows of data.</p>