Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.