Insert pandas dataframe
- async AsyncCogniteClient.time_series.data.insert_dataframe(
- df: pd.DataFrame,
- dropna: bool = True,
Insert a dataframe containing datapoints to one or more time series.
The index of the dataframe must contain the timestamps (pd.DatetimeIndex). The column identifiers must contain the IDs (
int), external IDs (str) or instance IDs (NodeIdor 2-tuple (space, ext. ID)) of the already existing time series to which the datapoints from that particular column will be written.Note
The column identifiers must be unique.
- Parameters:
df (pd.DataFrame) – Pandas DataFrame object containing the time series.
dropna (bool) – Set to True to ignore NaNs in the given DataFrame, applied per column. Default: True.
Warning
You can not insert datapoints with status codes using this method (
insert_dataframe), you’ll need to use theinsert()method instead (orinsert_multiple())!Examples
Post a dataframe with white noise to three time series, one using ID, one using external id and one using instance id:
>>> import numpy as np >>> import pandas as pd >>> from cognite.client import CogniteClient, AsyncCogniteClient >>> from cognite.client.data_classes.data_modeling import NodeId >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> node_id = NodeId("my-space", "my-ts-xid") >>> df = pd.DataFrame( ... { ... 123: np.random.normal(0, 1, 100), ... "foo": np.random.normal(0, 1, 100), ... node_id: np.random.normal(0, 1, 100), ... }, ... index=pd.date_range(start="2018-01-01", periods=100, freq="1d"), ... ) >>> client.time_series.data.insert_dataframe(df)