Solved

.csv file Ingestion into CDF using Python SDK


hello community, 

can anyone tell me is there any way to upload .csv files to CDF using Python SDK.

icon

Best answer by roman.chesnokov 24 May 2023, 09:30

View original

3 replies

Userlevel 3
Badge

To upload an actual file, check out:

https://cognite-sdk-python.readthedocs-hosted.com/en/latest/cognite.html#upload-a-file-or-directory

 

Or do you want to read the data and upload for example the rows as assets?

Userlevel 2

@Viswanadha Sai Akhil Pujyam to insert CSV as a RAW table, you can use the following snippet:

import numpy as np
import pandas as pd
from cognite.client import CogniteClient

DATABASE_NAME = "db"
TABLE_NAME = "table"
CSV_FILENAME = "source.csv"

client = CogniteClient()

client.raw.databases.create(DATABASE_NAME)
client.raw.tables.create(DATABASE_NAME, TABLE_NAME)

df = pd.read_csv(CSV_FILENAME, index_col=0).fillna('')

client.raw.rows.insert_dataframe(DATABASE_NAME, TABLE_NAME, df)

 

thank you roman_chesnokov

Reply