포스팅 목차
* 파이썬 & R 패키지 호출 및 예제 데이터 생성 링크
[ LN Oracle Function ]
LN함수는 지정한 수치형 인수의 자연로그 값을 계산한다. LN은 0보다 큰 값이다.
- 함수 설명 : LN 오라클 함수 링크
1. Oracle(오라클)
LN() 함수
Ln 함수를 사용하여서 95의 자연 로그값을 계산한다.
Oracle Programming |
SELECT LN(95) "Natural log of 95"
FROM DUAL;
Results |
Natural log of 95
-----------------------------------------
4.55387689160054083460978676511404117675
2. Python Pandas(파이썬)
log() 함수
Python Programming |
math.log(95)
Results |
4.553876891600541
math.log
Python Programming |
import copy
withmooc = copy.copy(emp)
withmooc['sal_log'] = withmooc['sal'].apply(math.log)
withmooc.head()
Results |
empno ename job mgr hiredate sal comm deptno sal_log
0 7369 SMITH CLERK 7902.0 1980/12/17 800 NaN 20 6.684612
1 7499 ALLEN SALESMAN 7698.0 1981/02/20 1600 300.0 30 7.377759
2 7521 WARD SALESMAN 7698.0 1981/02/22 1250 500.0 30 7.130899
3 7566 JONES MANAGER 7839.0 1981/04/02 2975 NaN 20 7.997999
4 7654 MARTIN SALESMAN 7698.0 1981/09/28 1250 1400.0 30 7.130899
3. R Programming (R Package)
log() 함수
R Programming |
%%R
log(95)
Results |
[1] 4.553877
sapply() 와 log
R Programming |
%%R
withmooc <- emp
withmooc['sal_log'] <- sapply(withmooc['sal'],log )
withmooc[1:10, ]
Results |
# A tibble: 10 x 9
empno ename job mgr hiredate sal comm deptno sal_log
<dbl> <chr> <chr> <dbl> <date> <dbl> <dbl> <dbl> <dbl>
1 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 6.68
2 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 7.38
3 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 7.13
4 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 8.00
5 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 7.13
6 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30 7.96
7 7782 CLARK MANAGER 7839 1981-01-09 2450 NA 10 7.80
8 7788 SCOTT ANALYST 7566 1982-12-09 3000 NA 20 8.01
9 7839 KING PRESIDENT NA 1981-11-17 5000 NA 10 8.52
10 7844 TURNER SALESMAN 7698 1981-09-08 1500 0 30 7.31
4. R Dplyr Package
log() 함수
Log 함수를 사용하여서 95의 자연 로그값을 계산한다.
R Programming |
%%R
emp %>%
mutate(sal_log = log(sal)) %>%
head(10)
Results |
# A tibble: 10 x 9
empno ename job mgr hiredate sal comm deptno sal_log
<dbl> <chr> <chr> <dbl> <date> <dbl> <dbl> <dbl> <dbl>
1 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 6.68
2 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 7.38
3 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 7.13
4 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 8.00
5 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 7.13
6 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30 7.96
7 7782 CLARK MANAGER 7839 1981-01-09 2450 NA 10 7.80
8 7788 SCOTT ANALYST 7566 1982-12-09 3000 NA 20 8.01
9 7839 KING PRESIDENT NA 1981-11-17 5000 NA 10 8.52
10 7844 TURNER SALESMAN 7698 1981-09-08 1500 0 30 7.31
5. R sqldf Package
log() 함수
Log 함수를 사용하여서 95의 자연 로그값을 계산한다.
R Programming |
%%R
sqldf(" SELECT log(95) ")
Results |
log(95)
1 4.553877
math.log()
R Programming |
import pandasql as ps
var = math.log(95)
query = "SELECT {} ".format(var)
ps.sqldf(query, globals())
Results |
4.553876891600541
0 4.553877
log() 함수
R Programming |
%%R
sqldf(" SELECT *,
log(sal) sal_log
from emp")[1:10, ]
Results |
empno ename job mgr hiredate sal comm deptno sal_log
1 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 6.684612
2 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 7.377759
3 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 7.130899
4 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 7.997999
5 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 7.130899
6 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30 7.955074
7 7782 CLARK MANAGER 7839 1981-01-09 2450 NA 10 7.803843
8 7788 SCOTT ANALYST 7566 1982-12-09 3000 NA 20 8.006368
9 7839 KING PRESIDENT NA 1981-11-17 5000 NA 10 8.517193
10 7844 TURNER SALESMAN 7698 1981-09-08 1500 0 30 7.313220
6. Python pandasql Package
log() 함수
Log 함수를 사용하여서 95의 자연 로그값을 계산한다.
Python Programming |
ps.sqldf(" SELECT log(95) ")
7. R data.table Package
log() 함수
Log 함수를 사용하여서 95의 자연 로그값을 계산한다.
R Programming |
%%R
DT <- data.table(emp)
dept_DT <- data.table(dept)
DT[,sal_log := log(sal)][1:10]
Results |
empno ename job mgr hiredate sal comm deptno sal_log
1: 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 6.684612
2: 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 7.377759
3: 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 7.130899
4: 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 7.997999
5: 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 7.130899
6: 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30 7.955074
7: 7782 CLARK MANAGER 7839 1981-01-09 2450 NA 10 7.803843
8: 7788 SCOTT ANALYST 7566 1982-12-09 3000 NA 20 8.006368
9: 7839 KING PRESIDENT NA 1981-11-17 5000 NA 10 8.517193
10: 7844 TURNER SALESMAN 7698 1981-09-08 1500 0 30 7.313220
8. Python DuckDB의 SQL
Python Programming |
%%sql
SELECT LN(95) AS Natural_log_of_95
Python Programming |
duckdb.sql(" SELECT LN(95) AS Natural_log_of_95 ").df()
Results |
Natural_log_of_95
0 4.553877
Python Programming |
%%sql
SELECT *,
LN(sal) sal_log
from emp
LIMIT 6
Python Programming |
duckdb.sql(" SELECT *, \
LN(sal) sal_log \
from emp \
LIMIT 6 ").df()
Results |
empno ename job mgr hiredate sal comm deptno sal_log
0 7369 SMITH CLERK 7902.0 1980/12/17 800 NaN 20 6.684612
1 7499 ALLEN SALESMAN 7698.0 1981/02/20 1600 300.0 30 7.377759
2 7521 WARD SALESMAN 7698.0 1981/02/22 1250 500.0 30 7.130899
3 7566 JONES MANAGER 7839.0 1981/04/02 2975 NaN 20 7.997999
4 7654 MARTIN SALESMAN 7698.0 1981/09/28 1250 1400.0 30 7.130899
5 7698 BLAKE MANAGER 7839.0 1981/03/01 2850 NaN 30 7.955074
--------------------------------------------
[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 예제로 만나는 테이블 데이터 처리 방법 리스트 링크 링크 |
반응형
댓글