Ask Your Question

How can Python script be used to convert an annotated CSV file in InfluxDB to a standard CSV file format?

asked 2021-11-24 11:00:00 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-04-10 15:00:00 +0000

plato gravatar image

To convert an annotated CSV file in InfluxDB to a standard CSV file format using Python, you can use the InfluxDB Python client module and the Pandas library. Here's an example code snippet:

import pandas as pd
from influxdb import InfluxDBClient

# Connect to InfluxDB
client = InfluxDBClient(host='localhost', port=8086, database='mydb')

# Query data from InfluxDB
results = client.query('SELECT * FROM my_measurement')

# Convert data to Pandas DataFrame
df = pd.DataFrame(list(results.get_points(measurement='my_measurement')))

# Remove InfluxDB metadata columns
df = df.drop(columns=['time', 'measurement', 'tags'])

# Write DataFrame to standard CSV file
df.to_csv('my_data.csv', index=False)

In this example, replace mydb with the name of your InfluxDB database, my_measurement with the name of your measurement, and my_data.csv with the name you want to give to your output CSV file. The code connects to the InfluxDB server, queries data from the specified measurement, converts the data to a Pandas DataFrame, removes the InfluxDB metadata columns (time, measurement, tags), and writes the DataFrame to a standard CSV file.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer

Question Tools


Asked: 2021-11-24 11:00:00 +0000

Seen: 17 times

Last updated: Apr 10 '22