How does Pandas to_sql determine what dataframe column is placed into what database field?

前端 未结 1 2092
陌清茗
陌清茗 2021-02-19 13:57

I\'m currently using Pandas to_sql in order to place a large dataframe into an SQL database. I\'m using sqlalchemy in order to connect with the database and part of that process

1条回答
  •  别跟我提以往
    2021-02-19 14:25

    The answer is indeed what you suggest: it is looking at the column names. So matching columns names is important, the order does not matter.

    To be fully correct, pandas will not actually check this. What to_sql does under the hood is executing an insert statement where the data to insert is provided as a dict, and then it is just up to the database driver to handle this.
    This also means that pandas will not check the dtypes or the number of columns (e.g. if not all fields of the database are present as columns in the dataframe, these will filled with a default value in the database for these rows).

    0 讨论(0)
提交回复
热议问题