Hi everyone! I’m new to InfluxDB and I’m trying to input data from .csv file using Python api. My code worked without problems but I notice that there was an unexpected string"\n" at the end of each of my data.
I don’t know exactly why this issue came out. Any suggestion would be helpful for me. Thank you.!
My code is as follows:
import datetime
import random
import time
import os
import csv
from csv import reader
import argparse
from influxdb import client as influxdb
client = influxdb.InfluxDBClient(host = ‘localhost’, port = 8086)
client.create_database(‘test_xufu’)
#print(client.get_list_database())
client.switch_database(‘test_xufu’)
def read_data(filename):
with open(filename) as f:
lines = f.readlines()[1:]
return lines
if name == ‘main’:
filename = r’/Users/chenayu/Desktop/test_xufu1.csv’
lines = read_data(filename)
for rawline in lines:
line = rawline.split(’,’)
dt = line[0]
json_body = [
{
“measurement”: “load”,
“tags”:{
“host”: “Xufu”,
“region”: “Lianyungang”
},
“time”: dt,
“fields”:{
“load”: line[1],
}
}
]
client.write_points(json_body)