我想将数据从CSV文件插入Influxdb。我已经尝试了以下Python脚本。成功,但是我希望在特定时间插入它(我有一列指定了日期)。
import pandas as pd
from influxdb import InfluxDBClient
client = InfluxDBClient(host='localhost', port=8086)
client.switch_database('databse_name')
file_path = r'file_name.csv'
csvReader = pd.read_csv(file_path)
print(csvReader.shape)
print(csvReader.columns)
for row_index, row in csvReader.iterrows() :
tags = row[1]
#fieldvalue = row[2]
json_body = [
{
"measurement": "Measurement_name",
"tags": {
"Tag_name1": tags
},
"fields": {
"Field1": row[2],
"Field2": row[3],
"Field3": row[4]
}
}
]
client.write_points(json_body)
答案 0 :(得分:2)
在json_body中指定time
:
json_body = [{
"time": "<datetime, e.g. 2020-05-02T17:30:45Z>",
"measurement": "Measurement_name",
"tags": {
"Tag_name1": tags
},
"fields": {
"Field1": row[2],
"Field2": row[3],
"Field3": row[4]
}
}]