Skip to content

Commit 5f286f5

Browse files
committed
docs: how to write Pandas DataFrame
1 parent b47e697 commit 5f286f5

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

MIGRATION_GUIDE.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ Please take a moment to review the following client docs:
1818
- [Initializing Client](#initializing-client)
1919
- [Creating Database/Bucket](#creating-databasebucket)
2020
- [Dropping Database/Bucket](#dropping-databasebucket)
21-
- [Writing LineProtocol](#writing-lineprotocol)
22-
- [Writing Dictionary-style object](#writing-dictionary-style-object)
21+
- Writes
22+
- [LineProtocol](#writing-lineprotocol)
23+
- [Dictionary-style object](#writing-dictionary-style-object)
24+
- [Pandas DataFrame](#writing-pandas-dataframe)
2325

2426
## Initializing Client
2527

@@ -191,6 +193,43 @@ with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org')
191193
```python
192194
```
193195

196+
## Writing Pandas DataFrame
197+
198+
**influxdb-python**
199+
200+
```python
201+
import pandas as pd
202+
203+
from influxdb import InfluxDBClient
204+
205+
df = pd.DataFrame(data=list(range(30)),
206+
index=pd.date_range(start='2014-11-16', periods=30, freq='H'),
207+
columns=['0'])
208+
209+
client = InfluxDBClient(host='127.0.0.1', port=8086, username='root', password='root', database='dbname')
210+
211+
client.write_points(df, 'demo', protocol='line')
212+
```
213+
214+
**influxdb-client-python**
215+
216+
```python
217+
import pandas as pd
218+
219+
from influxdb_client import InfluxDBClient
220+
from influxdb_client.client.write_api import SYNCHRONOUS
221+
222+
with InfluxDBClient(url='http://localhost:8086', token='my-token', org='my-org') as client:
223+
write_api = client.write_api(write_options=SYNCHRONOUS)
224+
225+
df = pd.DataFrame(data=list(range(30)),
226+
index=pd.date_range(start='2014-11-16', periods=30, freq='H'),
227+
columns=['0'])
228+
229+
write_api.write(bucket='my-bucket', record=df, data_frame_measurement_name='demo')
230+
231+
```
232+
194233
## Querying
195234

196235
**influxdb-python**

0 commit comments

Comments
 (0)