Why _time column has two values and how to get just one

So I’m trying to get a dataframe from the database and plot it with matplot

I’ve my query that get the data

from(bucket: “Bed1”)
|> range(start: 2023-06-22T14:10:36.106Z, stop: 2023-06-22T14:29:12.154Z)
|> filter(fn: (r) => r[“_measurement”] == “Postazione1”)
|> filter(fn: (r) => r[“TipoTest”] == “135”)
|> filter(fn: (r) => r[“_field”] == “Temperatura”)
|> aggregateWindow(every: 1s, fn: mean, createEmpty: false)
|> yield(name: “mean”)
|> pivot(rowKey:[“_time”], columnKey: [“_field”], valueColumn: “_value”)
|> keep(columns:[“_time”, “Temperatura”])

And when I print the data with

client = InfluxDBClient(url=influx_url, token=influx_token, org=influx_org, debug=False)
df = client.query_api().query_data_frame(org=influx_org, query=query)
df = pd.concat(df, axis=1)
df = df.drop(columns=[“result”, “table”, “_start”, “_stop”, “TipoTest”, “_field”, “_measurement”, “_value”])
df = df.set_index(“_time”)
df.head()

The _time column has two values in the form of

(2023-06-22 14:10:37+00:00, 2023-06-22 14:10:37+00:00)

How can I get just one timestamp

Hi,

Time column has two values start and stop. You can’t have only one timestamp. It will display the data betwen the startdate and stopdate.

But they both have the same value

Also, in this example hey have just one value Matplotlib Tutorial - Learn How to Visualize Time Series Data With Matplotlib and InfluxDB | InfluxData

In code you will use two time series start and stop, but it depends on visualization whether to display one or two

Sorry but I’m not understanding

For some reason df = client.query_api().query_data_frame returns a list with two dataframes

Using just the first or the second the _time filed has only a timestap and not two

I’m wondering why query_data_frame returns two data frames tho

I think @AVVS_Sudheer Is talkig of _start and _stop columns. Those are the values of the range in the query, and you can drop it if you don’t need those.

@NicoCaldo probably your issue is related more to the client than the influxDB, I haven’t seen duplicated time values but also I don’t work with python, so I cannot give you more advice. but maybe that client returns the timestamps in UTC and Local time and you happen to have the same Local time as the UTC?. This is just a wild guess I may be wrong (most likely I am).

Hi,

In the below query

client = InfluxDBClient(url=influx_url, token=influx_token, org=influx_org, debug=False)
df = client.query_api().query_data_frame(org=influx_org, query=query)
df = pd.concat(df, axis=1)
df = df.drop(columns=[“result”, “table”, “_start”, “_stop”, “TipoTest”, “_field”, “_measurement”, “_value”])
df = df.set_index(“_time”)
df.head()

If you keep
df = df.drop(columns=[“result”, “table”, “_start”, “_stop”, “TipoTest”, “_field”, “_measurement”, “_value”])

below
df = df.set_index(“_time”)

it will display only one time column.