Skip to main content
Question

Not able to run any python script in Jupiter Notebook Beta environment

  • July 14, 2026
  • 1 reply
  • 9 views

Forum|alt.badge.img
I am not able to run this python scipt even after trying for more than week. Could you please help me with this.
Name of topic ; Cognoite timeseries transformation.
This is my script:
# Insert datapoints into CogniteTimeSeries
from cognite.client import CogniteClient
from cognite.client.data_classes.data_modeling import NodeId
client = CogniteClient()
all_rows = client.raw.rows("IFSDB", "draft-values-test",partitions=5, chunk_size=1000, limit=5000
)
print("Ingesting datapoints ... please wait until is completed...")
for chunk_row in all_rows:
    for row_list in chunk_row:
        externalId = 'FirstnameBirthyear:' + row_list.columns['sensor']
        timestamp = row_list.columns['time_stamp']
        dp = row_list.columns['value']
        datapoints = [(timestamp, dp)]
        client.time_series.data.insert(datapoints, instance_id=NodeId("cdf-fundamentals", externalId))
print("All datapoints from table has been inserted into CogniteTimeSeries")

 

1 reply

Michael Bennett
Expert ⭐️⭐️⭐️⭐️
Forum|alt.badge.img+8
  • Expert ⭐️⭐️⭐️⭐️
  • July 14, 2026

Hi Yadav. Thanks for reaching out to Cognite. The query is making individual calls, and looping back over.  It’s. a long ride to 5k. 

 

Here’s the sequence of operations I would suggest:

 

  1. Fetch from Raw.
  2. Group data points by extid
  3. Insert the batched data points, and print the output of the payload.
from collections import defaultdict
from cognite.client import CogniteClient
from cognite.client.data_classes.data_modeling import NodeId

client = CogniteClient()

# 1. Fetch RAW rows
all_rows = client.raw.rows.list(
db_name="IFSDB",
table_name="draft-values-test",
limit=5000
)

# 2. Group datapoints by externalId in memory to batch them
# Structure: { NodeId: [(timestamp, value), (timestamp, value), ...] }
batched_data = defaultdict(list)

print("Processing and grouping RAW data...")
for row in all_rows:
sensor = row.columns.get('sensor')
timestamp = row.columns.get('time_stamp')
dp_value = row.columns.get('value')

# Skip row if any critical data is missing
if not (sensor and timestamp and dp_value is not None):
continue

instance_key = NodeId("cdf-fundamentals", f"FirstnameBirthyear:{sensor}")
batched_data[instance_key].append((timestamp, dp_value))

# 3. Insert the batched datapoints
print("Ingesting datapoints in batches...")
insert_payload = []
for instance_id, dps in batched_data.items():
insert_payload.append({
"instance_id": instance_id,
"datapoints": dps
})

# Cognite's SDK handles bulk list inserts beautifully
if insert_payload:
client.time_series.data.insert_multiple(insert_payload)
print(f"Successfully ingested data for {len(insert_payload)} unique time series.")
else:
print("No valid datapoints found to insert.")

Let me know if this addresses the issues you’re facing.

 

Regards,

MB