Insert pandas dataframe
- async AsyncCogniteClient.raw.rows.insert_dataframe(
- db_name: str,
- table_name: str,
- dataframe: pd.DataFrame,
- ensure_parent: bool = False,
- dropna: bool = True,
Insert pandas dataframe into a table.
Uses index for row keys.
- Parameters:
db_name (str) – Name of the database.
table_name (str) – Name of the table.
dataframe (pd.DataFrame) – The dataframe to insert. Index will be used as row keys.
ensure_parent (bool) – Create database/table if they don’t already exist.
dropna (bool) – Remove NaNs (but keep None’s in dtype=object columns) before inserting. Done individually per column. Default: True
Examples
Insert new rows into a table:
>>> import pandas as pd >>> from cognite.client import CogniteClient >>> >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> df = pd.DataFrame( ... {"col-a": [1, 3, None], "col-b": [2, -1, 9]}, index=["r1", "r2", "r3"] ... ) >>> res = client.raw.rows.insert_dataframe("db1", "table1", df, dropna=True)