influxdata / influxdb-python

Python client for InfluxDB
MIT License
1.69k stars 520 forks source link

issue loading pandas dataframe to influxDB #713

Open cppt opened 5 years ago

cppt commented 5 years ago

Version Spyder 3.3.2 Python 3.7 InfluxDB 1.7.6 Ubuntu 18.04

Trying to load a simple pandas dataframe to influxDB within python and getting the following error:

ValueError: Invalid time precision is given. (use 'n', 'u', 'ms', 's', 'm' or 'h')

Defaulted to the example presented in the help docs for pandas and getting the same error:


In [76]: dbname = 'demo'

In [77]: protocol = 'json'

In [78]: client = InfluxDBClient(host='localhost',port=8086)

In [79]: df = pd.DataFrame(data=list(range(30)),
    ...:                      index=pd.date_range(start='2014-11-16',
    ...:                                          periods=30, freq='h'), columns=['0'])

In [80]: client.create_database(dbname)

In [81]: client.write_points(df, 'demo', protocol=protocol)
Traceback (most recent call last):

  File "<ipython-input-81-11d3f1badbc5>", line 1, in <module>
    client.write_points(df, 'demo', protocol=protocol)

  File "/home/chris/anaconda3/lib/python3.7/site-packages/influxdb/client.py", line 490, in write_points
    tags=tags, protocol=protocol)

  File "/home/chris/anaconda3/lib/python3.7/site-packages/influxdb/client.py", line 519, in _write_points
    "Invalid time precision is given. "

ValueError: Invalid time precision is given. (use 'n', 'u', 'ms', 's', 'm' or 'h')
aniamirjanyan commented 4 years ago

You are getting an error because Influx doesn't accept start time as YYYY-MM-DD. It accepts this format --> YYYY-MM-DD HH:MM:SS (e.g. 2019-10-14 05:29:31)