pgcom.commuter.Commuter.insert¶
- Commuter.insert(table_name: str, data: pandas.core.frame.DataFrame, columns: Optional[List[str]] = None, placeholders: Optional[List[str]] = None) None [source]¶
Write rows from a DataFrame to a database table.
- Parameters
table_name – Name of the destination table.
data – Pandas.DataFrame with the data to be inserted.
columns – List of column names used for insert. If not specified then all the columns are used. Defaults to None.
placeholders – List of placeholders. If not specified then the default placeholders are used. Defaults to None.
Examples
>>> self.insert("people", data)
Insert two columns, name and age.
>>> self.insert("people", data, columns=["name", "age"])
You can customize placeholders to implement advanced insert, e.g. to insert geometry data in a database with PostGIS extension.
>>> self.insert( ... table_name="polygons", ... data=data, ... columns=["name", "geom"], ... placeholders=["%s", "ST_GeomFromText(%s, 4326)"])