How to read a property at [index, string]
?
#1094
Replies: 6 comments
-
Seems like maybe a workaround could be: (->> data .loc (drop 2) (take 1) (map #(.-Name %)) first)
;;=> "John Holland" |
Beta Was this translation helpful? Give feedback.
-
HI @johnjelinek, this would be > basilisp repl
basilisp.user=> (import [pandas :as pd]) nil
nil
basilisp.user=> (def data (pd/read_csv "https://media.geeksforgeeks.org/wp-content/uploads/nba.csv"))
(-> data .iloc (subvec 0 3))
Name Team Number Position Age Height Weight College Salary
0 Avery Bradley Boston Celtics 0.0 PG 25.0 6-2 180.0 Texas 7730337.0
1 Jae Crowder Boston Celtics 99.0 SF 25.0 6-6 235.0 Marquette 6796117.0
2 John Holland Boston Celtics 30.0 SG 27.0 6-5 205.0 Boston University NaN
basilisp.user=> (aget (.-at data) #py (2 "Name"))
"John Holland" Please also have a look at https://github.com/ikappaki/basilisp-kernel/blob/main/notebooks/pandas-03-select.ipynb where I replicated some examples from the pandas getting started guide for the Basilisp Kernel. Pandas makes heavy use of overloaded indexing operators, including I hope this helps |
Beta Was this translation helpful? Give feedback.
-
Thanks, is there another way to write the following? #py (2 "Name") I tried: (lisp->py (list 2 "Name"))
;;=> #py [2 "Name"] and that didn't pass into |
Beta Was this translation helpful? Give feedback.
-
The Another way to write this is to use the basilisp.user=> (def t (tuple [2 "Name"]))
#'basilisp.user/t
basilisp.user=> t
#py (2 "Name")
basilisp.user=> (type t)
<class 'tuple'>
basilisp.user=> (aget (.-at data) (tuple [2 "Name"]))
"John Holland" |
Beta Was this translation helpful? Give feedback.
-
can also do |
Beta Was this translation helpful? Give feedback.
-
Seems to me like a decent use case for a specialized library with macros to handle Pandas/Polars/etc. APIs. |
Beta Was this translation helpful? Give feedback.
-
Given the following example:
How do I call the
.at[position, label]
part?I tried:
Beta Was this translation helpful? Give feedback.
All reactions