T2020
T2020

Reputation: 71

Problem with inserting pandas dataframe into influxdb

I am trying to write data into influxdb and querying it to return the data but all I am getting is empty dataframe. I have used official influxdb documentation by creating a dataframe and writing and that works fine. But when I import a csv/pickle file as dataframe and try to insert, nothing is inserted or returned.

I am using influxdb 2.0.

I have two columns and one of them is "Time". The value looks like this.

"2020-01-01 01:00:00". I have set this column as index. I have used below code which works fine and can fetch data.

_now = datetime.now(UTC)
_data_frame = pd.DataFrame(data=[["coyote_creek", 1.0], ["coyote_creek", 2.0]],
                               index=[_now, _now + timedelta(hours=1)],
                               columns=["location", "water_level"])

_write_client.write("my-bucket", "my-org", record=_data_frame, data_frame_measurement_name='h2o_feet',
                        data_frame_tag_columns=['location'])

But when ever I use imported file, nothing gets inserted or gets fetched. I am using below code for importing and writing.

   _data_frame = pandas.read_pickle("sample.pickle")
   _data_frame.set_index('Time')


    _write_client.write("my-bucket", "my-org", record=_data_frame, data_frame_measurement_name='sample-data',
                        data_frame_tag_columns=['sample'])

Do I need to change my time format? If so how or which format?

This is the documentation link that I am using. https://github.com/influxdata/influxdb-client-python

Upvotes: 1

Views: 1499

Answers (1)

Jakub Bednář
Jakub Bednář

Reputation: 96

you have to use the result of _data_frame.set_index('Time').

Try this:

_data_frame = _data_frame.set_index('Time')

Regards

Upvotes: 0

Related Questions