Skip to content

Commit 6703a01

Browse files
committed
Merge branch 'master' of github.com:clj-python/libpython-clj
2 parents ab270cd + fbf719a commit 6703a01

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/Usage.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ item access is optional and happens via the `__getitem__` and `__setitem__` attr
88
This is important to realize in that the code below doesn't look like python because we are
99
referencing the item and attribute systems by name and not via '.' or '[]'.
1010

11+
This would result in the following analogous code (full example [further on](#dataframe-access-full-example)):
12+
13+
```python
14+
table.loc[row_date]
15+
```
16+
17+
```clojure
18+
(get-item (get-attr table :loc) row-date)
19+
```
1120

1221
### Installation
1322

@@ -216,6 +225,31 @@ user> (att-type-map ones-ary)
216225
}
217226
```
218227

228+
### DataFrame access full example
229+
230+
Here's how to create Pandas DataFrame and accessing its rows via `loc` in both Python and Clojure:
231+
232+
```python
233+
# Python
234+
import numpy as np
235+
import pandas as pan
236+
237+
dates = pan.date_range("1/1/2000", periods=8)
238+
table = pan.DataFrame(np.random.randn(8, 4), index=dates, columns=["A", "B", "C", "D"])
239+
row_date = pan.date_range(start="2000-01-01", end="2000-01-01")
240+
table.loc[row_date]
241+
```
242+
243+
```clojure
244+
; Clojure
245+
(require-python '[numpy :as np])
246+
(require-python '[pandas :as pan])
247+
248+
(def dates (pan/date_range "1/1/2000" :periods 8))
249+
(def table (pan/DataFrame (call-attr np/random :randn 8 4) :index dates :columns ["A" "B" "C" "D"]))
250+
(def row-date (pan/date_range :start "2000-01-01" :end "2000-01-01"))
251+
(get-item (get-attr table :loc) row-date)
252+
```
219253

220254
### Errors
221255

0 commit comments

Comments
 (0)