InfluxDBClientError: 400 writing df points #558
Description
Hello,
I'm in need of some help with inserting a df into influxdb.
My code:
print("Create pandas DataFrame")
df = pd.read_csv('../var/demo.csv')
print df
df.index = pd.Series([dt.datetime.now()] * len(df))
print df
print("Write DataFrame with Tags")
tags = {'COLUMN1': df['COLUMN1'], 'COLUMN2': df['COLUMN2']}
client.write_points(df, tbName, tags=tags, protocol='json')
Output:
Create pandas DataFrame
COLUMN1 COLUMN2
0 line1 value1
1 line2 value2
COLUMN1 COLUMN2
2018-01-18 17:05:12.859 line1 value1
2018-01-18 17:05:12.859 line2 value2
Write DataFrame with Tags
On write_points I get the exception:
influxdb.exceptions.InfluxDBClientError: 400: {"error":"partial write:\nunable to parse 'testdb,COLUMN1=2018-01-18\ 17:05:12.859\ \ \ \ line1': missing fields\nunable to parse '2018-01-18\ 17:05:12.859\ \ \ \ line2': missing fields\nunable to parse 'Name:\
COLUMN1\,\ dtype:\ object,COLUMN2=2018-01-18\ 17:05:12.859\ \ \ \ value1': missing fields\nunable to parse '2018-01-18\ 17:05:12.859\ \ \ \ value2': missing fields\nunable to parse 'testdb,COLUMN1=2018-01-18\ 17:05:12.859\ \ \ \ line1': missing field
s\nunable to parse '2018-01-18\ 17:05:12.859\ \ \ \ line2': missing fields\nunable to parse 'Name:\ COLUMN1\,\ dtype:\ object,COLUMN2=2018-01-18\ 17:05:12.859\ \ \ \ value1': missing fields\nunable to parse '2018-01-18\ 17:05:12.859\ \ \ \ value2':
missing fields"}
If i run write_points without tags: client.write_points(df, tbName, protocol='json')
Execution completed but only one line is inserted.
Without setting the index I just get:
TypeError: Must be DataFrame with DatetimeIndex or PeriodIndex.
.csv file is just 3 lines:
COLUMN1,COLUMN2
line1,value1
line2,value2
I searched around, but no similar issues, #549 has the same error but different context.
Using python 2.7 and influxdb 5.0
>python --version
Python 2.7.14
>pip show influxdb
Name: influxdb
Version: 5.0.0
Summary: InfluxDB client
Home-page: https://github.com/influxdb/influxdb-python
Author: UNKNOWN
Author-email: UNKNOWN
License: MIT License
Location: c:\python27\lib\site-packages
Requires: requests, python-dateutil, six, pytz