Closed shnabin closed 4 years ago
Hello @krishnacy
Sorry for the delay.
Your par is not list type nor str type. The par is the <class 'pandas.core.indexes.base.Index'>
Consider you use the pandas, suggest to convert to list as following.
par = list(par)
Here is the full code:
from ExportCsvToInflux import ExporterObject
import pandas as pd
exporter = ExporterObject()
path = r'data.csv'
df = pd.read_csv(path)
par = df.columns[2:104]
print(type(par))
print(par)
par = list(par)
print(par)
exporter.export_csv_to_influx(csv_file=r'data.csv',
db_name='mydb',
db_measurement='demo',
time_column='Time',
tag_columns=par,
field_columns='Blo',
db_user='admin',
db_password='',
force_insert_even_csv_no_update=True,
db_server_name='localhost:8086',
time_format='%H:%M')
Hi @Bugazelle
Thank you for the support. Sorry for the delay in replying. Works perfectly now!!!
Cheers!!
Hi @Bugazelle ,
I'm trying to read a csv into influxdb with almost 100+ tags, i read the tags into a variable and tried using that variable against the tag_columns but its not working, I'm not sure how to pass these many tags. Is there a way to pass these tags to the tags_columns instead of manually entering them.
from ExportCsvToInflux import ExporterObject from influxdb import InfluxDBClient exporter = ExporterObject() import pandas as pd path = r'G:\data.csv' df = pd.read_csv(path) par=df.columns[2:104] print (par) exporter.export_csv_to_influx (csv_file =r'G:\data.csv' db_name= 'mydb', db_measurement= 'demo', time_column= 'Time', tag_columns= par, field_columns= 'Blo', db_user= 'admin', db_password= '', force_insert_even_csv_no_update= True, db_server_name= 'localhost:8086', time_format='%H:%M')
The output is as follows:
Index(['dat1', 'dat2', 'dat3', 'dat4', 'dat5', 'dat6', 'dat7', 'dat8', 'dat9', 'dat10', ... 'dat93', 'dat94', 'dat95', 'dat96', 'dat97', 'dat98', 'dat99', 'dat100', 'dat101', 'dat102'], dtype='object', length=102) Traceback (most recent call last): File "<pyshell#17>", line 11, in
time_format='%H:%M')
File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ExportCsvToInflux\exporter_object.py", line 175, in export_csv_to_influx
field_columns = base_object.str_to_list(field_columns)
File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ExportCsvToInflux\base_object.py", line 33, in str_to_list
elif bool(string) is False:
File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\indexes\base.py", line 2387, in nonzero
self.class.name
ValueError: The truth value of a Index is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
My csv is as follows:
Thank you for your support.