Python pandas 插入数据库的行数

Python pandas how many rows insert into DB

我使用 pandas 中的 TO_SQL 函数将数据从 DF 插入到 Oracle 中的 table 中。 我想在完成操作后检查追加到 table 的记录数量。 可以做到吗?怎么做? 谢谢

pandas.DataFrame.to_sql returns 自动受影响的行数。

amount_of_rows = pd.to_sql(name, connection)

# Setting it to 0 if the database returned no rows.
if not amount_of_rows:
    amount_of_rows = 0

# Printing out the amount.
print(f"{amount_of_rows} rows were inserted.")

查询运行成功则输出'X rows were inserted'。

P.S:1.4.0 之前的版本不支持 Returns。