【问题标题】:Python: write Dataframe to influxdbPython:将 Dataframe 写入 influxdb
【发布时间】:2023-03-18 07:53:01
【问题描述】:

我刚开始在 python 中使用 influxdb 客户端。我正在尝试将 Dataframe 写入 influxdb。基于

https://influxdb-python.readthedocs.io/en/latest/examples.html#tutorials-pandas

我可以使用 DataFrameClient 来做到这一点。

我的数据:

                              Val1        Val2       S_id   Formula
          Date              
2020-01-01 01:00:00+00:00   26.131181   12.537605   35211   soneja
2020-01-01 01:15:00+00:00   21.459827   10.671435   35211   soneja
...     ...     ...     ...     ...
2020-01-21 00:45:00+00:00   13.257205   4.322372    35211   soneja
2020-01-21 01:00:00+00:00   13.520987   4.393989    35211   soneja

1901 rows × 4 columns

我将数据发送到 influxdb 的代码:

from influxdb import DataFrameClient
client = DataFrameClient(host, port, user, password, dbname)
client.write_points(df, dbname, protocol='line')

我得到的错误:

('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

        

【问题讨论】:

    标签: python dataframe influxdb


    【解决方案1】:

    我认为这与您的 influxdb 设置和网络有关。对我来说这是可行的:

    from influxdb import DataFrameClient
    client = DataFrameClient(host="localhost", port=8086)
    client.create_database("data")
    client.write_points(
        df,
        "measurement1",
        database="data",
        protocol="line",
        batch_size=1000,
    )
    

    【讨论】:

      猜你喜欢
      • 2017-09-26
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 2021-03-22
      • 2018-10-05
      • 2019-05-22
      相关资源
      最近更新 更多