I am facing an issue while trying to write into InfluxDB 2.7 with python library influxdb-client==1.48.0.
I have created a pandas DataFrame with this schema:
signalname float64
imo object
dtype: object
Here is a df.head() example:
_time signalname tag_number
1744784582000000000 1.01591 8842250
1744784589000000000 1.01550 8842250
1744784599000000000 1.01580 8842250
1744784609000000000 1.01560 8842250
1744784619000000000 1.01550 8842250
_time column is the index of the DF and it’s in Nanoseconds.
Here is the code snippet I use:
tags = ['tag_number']
source = 'source1'
with InfluxDBClient(
url=influx_url,
token=influx_token,
org=influx_org
) as client:
write_api = client.write_api(
write_options=WriteOptions(batch_size=influx_batch_size)
)
write_api.write(
influx_bucket,
influx_org,
record=df,
data_frame_tag_columns=tags,
data_frame_measurement_name=source,
)
write_api.close()
On every call to write_api.write(…) I get the following exception:
cannot do slice indexing on DatetimeIndex with these indexers [] of type str
Can somebody help?
