-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to write Pandas Dataframe #169
Comments
Hi @stepanurban, Thanks for using our client. How do you create the The default instance of Please check following code: from datetime import datetime, timedelta
import numpy as np
import pandas as pd
from influxdb_client import InfluxDBClient
from influxdb_client.client.write.dataframe_serializer import data_frame_to_list_of_points
from influxdb_client.client.write_api import PointSettings
"""
Prepare Client
"""
org = "my-org"
bucket = "my-bucket"
token = "my-token"
client = InfluxDBClient(url="http://localhost:8086", token=token, org=org)
"""
Prepare DataFrame
"""
date_today = datetime.now()
days = pd.date_range(date_today, date_today + timedelta(7), freq='D')
np.random.seed(seed=1111)
data = np.random.randint(1, high=100, size=len(days))
df = pd.DataFrame({'date': days, 'col2': data})
df = df.set_index('date')
print(df)
"""
Check Generated LineProtocol
"""
points = data_frame_to_list_of_points(data_frame=df,
point_settings=PointSettings(),
data_frame_measurement_name='meas')
print(points)
"""
Ingest DataFrame
"""
_write_client = client.write_api()
_write_client.write(bucket, org, record=df, data_frame_measurement_name='meas')
# Flush changes
_write_client.__del__()
"""
Querying ingested data
"""
query = f'from(bucket:"{bucket}")' \
' |> range(start: 0, stop: 10d)' \
' |> filter(fn: (r) => r._measurement == "meas")'
result = client.query_api().query(query=query)
"""
Processing results
"""
print()
print("=== results ===")
print()
for table in result:
for record in table.records:
print('{0}: {1} = {2}'.format(record["_time"], record["_field"], record["_value"]))
"""
Close client
"""
client.__del__() Regards |
Hi @bednar,
due to NaN values in the dataframe. When you will change data = np.empty(len(days))
data[:] = np.NaN you can get this response. How can I cope with NaNs? |
The Following data are pretty fine: data = np.random.randint(1, high=100, size=len(days))
df = pd.DataFrame({'date': days, 'col2': data, 'col3': np.NaN}) |
Sorry for wrong example. For integer it works fine unfortunately the error arise when there are floats with NaNs data = np.random.random(len(days))
data[0] = np.NaN
df = pd.DataFrame({'date': days, 'col2': data})
df = df.set_index('date') |
Thanks, I see... there is the LineProtocol without fields:
I will take a look |
Hi @stepanurban, the issue is fixed in #170. You could try a dev version by:
Regards |
Works perfectly thanks! |
Hi there,
I'm not able to write pandas dataframe into Influx 2.0
There is only empty measurement meas. There is no output of the command even when Debug=True. What's wrong?
The text was updated successfully, but these errors were encountered: