포스팅 목차
* 파이썬 & R 패키지 호출 및 예제 데이터 생성 링크
[ ABS 함수 ]
사용자가 지정한 인수의 절대값을 구한다.
- 함수설명 : ABS 오라클 함수 링크
1. Oracle(오라클)
Oracle Programming |
SELECT ABS(-15) "Absolute"
FROM DUAL;
Results |
Absolute
15
Oracle Programming |
SELECT AVG(sal) AVG
FROM emp
GROUP
BY DEPTNO
2. Python Pandas(파이썬)
Python Programming |
abs(-15)
Results |
15
Python Programming |
emp.sal.abs().head()
Results |
0 800
1 1600
2 1250
3 2975
4 1250
Name: sal, dtype: int64
3. R Programming (R Package)
R Programming |
%%R
abs(-15)
Results |
15
R Programming |
abs(emp['sal'])[0:5]
Results |
0 800
1 1600
2 1250
3 2975
4 1250
Name: sal, dtype: int64
4. R Dplyr Package
R Programming |
%%R
emp%>%
dplyr::mutate(sal_abs = abs(sal)) %>%
head()
Results |
# A tibble: 6 x 9
empno ename job mgr hiredate sal comm deptno sal_abs
1 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 800
2 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 1600
3 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 1250
4 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 2975
5 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 1250
6 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30 2850
5. R sqldf Package
R Programming |
%%R
sqldf(" SELECT ABS(-15) Absolute ")
Results |
Absolute
1 15
R Programming |
%%R
sqldf(" SELECT abs(sal) Absolute,* from emp") %>% head()
Results |
Absolute empno ename job mgr hiredate sal comm deptno
1 800 7369 SMITH CLERK 7902 1980-12-17 800 NA 20
2 1600 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30
3 1250 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30
4 2975 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20
5 1250 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30
6 2850 7698 BLAKE MANAGER 7839 1981-03-01 2850 NA 30
6. Python pandasql Package
Python Programming |
ps.sqldf(" SELECT ABS(-15) Absolute ")
Results |
Absolute
0 15
Python Programming |
ps.sqldf(" SELECT abs(sal) Absolute, * from emp ").head()
Results |
Absolute empno ename job mgr hiredate sal comm deptno
0 800 7369 SMITH CLERK 7902.0 1980/12/17 800 NaN 20
1 1600 7499 ALLEN SALESMAN 7698.0 1981/02/20 1600 300.0 30
2 1250 7521 WARD SALESMAN 7698.0 1981/02/22 1250 500.0 30
3 2975 7566 JONES MANAGER 7839.0 1981/04/02 2975 NaN 20
4 1250 7654 MARTIN SALESMAN 7698.0 1981/09/28 1250 1400.0 30
7. R data.table Package
Oracle Programming |
%%R
DT <- data.table(emp)
dept_DT <- data.table(dept)
DT[, sal_abs := abs(sal)][0:5]
Results |
empno ename job mgr hiredate sal comm deptno sal_abs
1: 7369 SMITH CLERK 7902 1980-12-17 800 NA 20 800
2: 7499 ALLEN SALESMAN 7698 1981-02-20 1600 300 30 1600
3: 7521 WARD SALESMAN 7698 1981-02-22 1250 500 30 1250
4: 7566 JONES MANAGER 7839 1981-04-02 2975 NA 20 2975
5: 7654 MARTIN SALESMAN 7698 1981-09-28 1250 1400 30 1250
8. Python DuckDB의 SQL
Python Programming |
%%sql
select abs(-15) as abs_1
Python Programming |
duckdb.sql("select abs(-15) as abs_1").df()
Results |
abs_1
15
[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 예제로 만나는 테이블 데이터 처리 방법 리스트 링크 링크 |
반응형
댓글