Skip to content

Commit 758c6dd

Browse files
committed
docs: added example with ingesting DataFrame and default tags
1 parent 2059d25 commit 758c6dd

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
How to ingest DataFrame with default tags.
3+
"""
4+
5+
import pandas as pd
6+
7+
from influxdb_client import InfluxDBClient
8+
from influxdb_client.client.write_api import SYNCHRONOUS, PointSettings
9+
10+
"""
11+
Load DataFrame form CSV File
12+
"""
13+
df = pd.read_csv("vix-daily.csv")
14+
print(df.head())
15+
16+
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
17+
18+
"""
19+
Ingest DataFrame with default tags
20+
"""
21+
point_settings = PointSettings(**{"type": "vix-daily"})
22+
point_settings.add_default_tag("example-name", "ingest-data-frame")
23+
24+
write_api = client.write_api(write_options=SYNCHRONOUS, point_settings=point_settings)
25+
write_api.write(bucket="my-bucket", record=df, data_frame_measurement_name="financial-analysis-df")
26+
27+
"""
28+
Querying ingested data
29+
"""
30+
query = 'from(bucket:"my-bucket")' \
31+
' |> range(start: 0, stop: now())' \
32+
' |> filter(fn: (r) => r._measurement == "financial-analysis-df")' \
33+
' |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")' \
34+
' |> limit(n:10, offset: 0)'
35+
result = client.query_api().query(query=query)
36+
37+
"""
38+
Processing results
39+
"""
40+
print()
41+
print("=== results ===")
42+
print()
43+
for table in result:
44+
for record in table.records:
45+
print('{4}: Open {0}, Close {1}, High {2}, Low {3}'.format(record["VIX Open"], record["VIX Close"],
46+
record["VIX High"], record["VIX Low"],
47+
record["type"]))
48+
49+
"""
50+
Close client
51+
"""
52+
client.__del__()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy