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.
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
Asked: 2021-11-24 11:00:00 +0000
Seen: 21 times
Last updated: Apr 10 '22