Skip to content

Commit 37b3f49

Browse files
committed
Added docs on integrating with pandas
1 parent eeda669 commit 37b3f49

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/rows.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,32 @@ selected via a `format` argument. The following table defined the possible value
150150
| `xml` | XML document defining the columns and rows. |
151151
| `csv` | CSV text with the first row defining the columns. |
152152
| `json-seq` | A [line-delimited JSON sequence](https://datatracker.ietf.org/doc/html/rfc7464) with the first row defining the columns. |
153+
154+
## Integration with pandas
155+
156+
[pandas](https://pandas.pydata.org/) is a widely used data analysis tool. A
157+
[pandas DataFrame](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) can easily be
158+
constructed by retrieving rows via `format=csv` and invoking
159+
[`pandas.read_csv`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html).
160+
161+
The following example assumes that you have pandas available in your Python shell already. If not, exit your shell,
162+
run `pip install pandas`, and then restart your shell, re-creating the `client` object as shown at the top of this
163+
page.
164+
165+
```
166+
import io
167+
import pandas
168+
169+
rows = client.rows.query("op.fromView('example', 'musician')", format="csv")
170+
df = pandas.read_csv(io.StringIO(rows))
171+
```
172+
173+
Printing the `df` object will yield the following:
174+
175+
```
176+
example.musician.lastName example.musician.firstName example.musician.dob
177+
0 Byron Don 1958-11-08
178+
1 Davis Miles 1926-05-26
179+
2 Armstrong Louis 1901-08-04
180+
3 Coltrane John 1926-09-23
181+
```

0 commit comments

Comments
 (0)