Reputation: 81
I am trying to write data from a panda's dataframe to influxdb v2.2 using python. However, I am not seeing any data in query.
import pandas as pd
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import SYNCHRONOUS
with InfluxDBClient(url="http://10.99.134.240:80", token="9npAT1nMuDjRbUg32qpLaJ1NntAYdhSu", org="influxdata") as client:
write_api = client.write_api(write_options=SYNCHRONOUS)
#df = pd.DataFrame(data=list(range(30)), index=pd.date_range(start='2014-11-16', periods=30, freq='H'), columns=['0'])
df = pd.DataFrame(data=list(range(30)), index=pd.date_range(start='2023-01-01', periods=30, freq='H'), columns=['0'])
print(df)
write_api.write(bucket='mybucket', record=df, data_frame_measurement_name='demo')
I am running below query on my terminal to get the written data. But nothing is returned, be it any range value.
influx query 'from(bucket:"mybucket") |> range(start:-5m)'
what could be the issue?
thanks
Upvotes: 1
Views: 1255
Reputation: 21
What worked for me is giving the timestamp column a name and passing that name to the write
method using the parameter data_frame_timestamp_column
.
df = pd.DataFrame(data={'Time': pd.date_range(start='2023-01-01', periods=30, freq='H'), 'Value': list(range(30))})
write_api.write(bucket='mybucket', record=df, data_frame_measurement_name='demo', data_frame_timestamp_column='Time')
Upvotes: 1