포스팅 목차
* 파이썬 & R 패키지 호출 및 예제 데이터 생성 링크
[ COSH Oracle Function ]
COSH은 파라미터 n(라디안으로 표현되는 각도)의 쌍곡 코사인값(hyperbolic cosine)을 반환한다.
- 함수설명 : COSH 오라클 함수 링크
1. Oracle(오라클)
Oracle Programming |
SELECT COSH(0) "Hyperbolic cosine of 0"
FROM DUAL;
Results |
Hyperbolic cosine of 0
----------------------------------
1
2. Python Pandas(파이썬)
Python Programming |
math.cosh(0)
Results |
1.0
Python Programming |
emp['sal'].apply(lambda x: math.cosh(x/1000)).head()
Results |
0 1.337435
1 2.577464
2 1.888424
3 9.820335
4 1.888424
Name: sal, dtype: float64
3. R Programming (R Package)
R Programming |
%%R
cosh(0)
R Programming |
%%R
cosh(emp$sal / 1000)
Results |
[1] 1.337435 2.577464 1.888424 9.820335 1.888424 8.672813 5.837320
[8] 10.067662 74.209949 2.352410 1.668519 1.486225 10.067662 1.970914
4. R Dplyr Package
R Programming |
%%R
emp %>%
dplyr::mutate(sal_cosh = cosh(sal / 1000)) %>%
head()
Results |
# A tibble: 6 x 9
empno ename job mgr hiredate sal comm deptno sal_cosh
<dbl> <chr> <chr> <dbl> <date> <dbl> <dbl> <dbl> <dbl>
1 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 1.34
2 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 2.58
3 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 1.89
4 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 9.82
5 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 1.89
6 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30 8.67
5. R sqldf Package
R Programming |
%%R
sqldf(" SELECT COSH(0) Hyperbolic_cosine_of_0 ")
Results |
Hyperbolic_cosine_of_0
1 1
R Programming |
%%R
sqldf(" SELECT COSH(sal / 1000) Hyperbolic_cosine_of_0 from emp ")[1:5 ,]
Results |
[1] 1.337435 2.577464 1.888424 9.820335 1.888424
6. Python pandasql Package
Python Programming |
ps.sqldf(" SELECT COSH(0) Hyperbolic_cosine_of_0 ")
Python Programming |
import pandasql as ps
var = math.cosh(0)
query = "SELECT {} ".format(var)
ps.sqldf(query, globals())
Results |
1.0
0 1.0
7. R data.table Package
R Programming |
%%R
DT <- data.table(emp)
dept_DT <- data.table(dept)
DT[, sal_cos := cosh(sal / 1000)][1:5, ]
Results |
empno ename job mgr hiredate sal comm deptno sal_cos
1: 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 1.337435
2: 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 2.577464
3: 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 1.888424
4: 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 9.820335
5: 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 1.888424
8. Python DuckDB의 SQL
* 현재 DuckDB 에서는 COSH 함수를 직접적으로 지원하지 않는다.
Python Programming |
%%sql
SELECT ((exp((0.5 * 2)) + 1) / (exp(0.5) * 2)) "Hyperbolic cosine of 0"
Python Programming |
duckdb.sql(' SELECT ((exp((0.5 * 2)) + 1) / (exp(0.5) * 2)) "Hyperbolic cosine of 0" ').df()
Results |
Hyperbolic cosine of 0
0 1.127626
--------------------------------------------
[Oracle, Pandas, R Prog, Dplyr, Sqldf, Pandasql, Data.Table] 오라클 함수와 R & Python 비교 사전 목록 링크 |
오라클 SQL 함수(Oracle SQL Function) 목록 리스트 링크 |
[SQL, Pandas, R Prog, Dplyr, SQLDF, PANDASQL, DATA.TABLE] SQL EMP 예제로 만나는 테이블 데이터 처리 방법 리스트 링크 링크 |
반응형
댓글