0

There seems to be no documentation on how to use hy on single column pandas operation such as the following. Would appreciate any help:

# simple instantiation to scalar
df['a'] = '2'
# the above can be done like so: (-> df (.assign :a "2")) but would appreciate any better ways

# cast a column to int
df['a'] = df['a'].astype(int)
# creating  derived columns
df['c'] = df['a'] + df['b']
#subsetting by columns
dd = df[['a','b']]
#subsetting by criteria
dd = df[(df['a'] > 1) & (df['b'] < 2)]
dedupe
  • 9
  • 2

1 Answers1

0

pandas doesn't actually change the syntax or semantics of Python itself; it just uses operator overloading. So you can use the Hy equivalents of the same operators without issues, although helper macros can make pandas a lot more convenient.

; simple instantiation to scalar
(setv (get df "a") "2")
; cast a column to int
(setv (get df "a") (.astype (get df "a") int))
; creating  derived columns
(setv (get df "c") (+ (get df "a") (get df "c")))
;subsetting by columns
(setv dd (get df ["a" "b"]))
;subsetting by criteria
(setv dd (get df (& (> (get df "a") 1) (< (get df "b") 2))))
Kodiologist
  • 2,984
  • 18
  • 33
  • outstanding ! Would also appreciate some examples on how to use your macros. – dedupe Oct 16 '20 at 11:52
  • @dedupe Check the comments and docstrings (for which you may still have to read the source code, since currently, macro docstrings aren't terribly accessible at run time). – Kodiologist Oct 16 '20 at 17:17