1

i am trying to use python's package for influxdb to upload dataframe into the database i am using the write_points class to write point into the database as given in the documentation(https://influxdb-python.readthedocs.io/en/latest/api-documentation.html)

every time i try to use the class it only updates the last line of the dataframe instead of the complete dataframe.

is this a usual behavior or there is some problem here?

given below is my script:

from influxdb import InfluxDBClient, DataFrameClient
import pathlib 
import numpy as np
import pandas as pd
import datetime

db_client = DataFrameClient('dbserver', port, 'username', 'password', 'database', 
                            ssl=True, verify_ssl=True)



today = datetime.datetime.now().strftime('%Y%m%d')
path = pathlib.Path('/dir1/dir/2').glob(f'pattern_to_match*/{today}.filename.csv')
for file in path:
    order_start = pd.read_csv(f'{file}')
    
    if not order_start.empty:
        order_start['data_line1'] = (order_start['col1'] - \ 
                                   order_start['col2'])*1000
        order_start['data_line2'] = (order_start['col3'] - \ 
                                   order_start['col4'])*1000
        d1 = round(order_start['data_line1'].quantile(np.arange(0,1.1,0.1)), 3)
        d2 = round(order_start['data_line2'].quantile(np.arange(0,1.1,0.1)), 3)
    
        out_file = pd.DataFrame()
        out_file = out_file.append(d1)
        out_file = out_file.append(d2)
        out_file = out_file.T
        out_file.index = out_file.index.set_names(['percentile'])
        out_file = out_file.reset_index()
        out_file['percentile'] = out_file.percentile.apply(lambda x: f'{100*x:.0f}%')
        out_file['tag_col'] = str(file).split('/')[2]
        out_file['time'] = pd.to_datetime('today').strftime('%Y%m%d')
        out_file = out_file.set_index('time')
        out_file.index = pd.to_datetime(out_file.index)
        db_client.write_points(out_file, 'measurement', database='database', 
                               retention_policy='rp')

can anyone please help?

0 Answers0