Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- ASP
- MySQL
- 리눅스
- tensorflow
- Excel
- node.js
- sqlite
- Unity
- urllib
- pandas
- flutter
- javascript
- MS-SQL
- port
- swift
- python
- 라즈베리파이
- IOS
- 맛집
- 함수
- PyQt
- PyQt5
- Linux
- GIT
- 유니티
- mssql
- PER
- ubuntu
- 다이어트
- 날짜
Archives
아미(아름다운미소)
백터화 본문
import pandas as pd
import numpy as np
def p_location_vectorized(df, p_location_col):
# 벡터화된 연산을 위해 numpy의 where 함수를 사용
df['return_value'] = np.where(
df[p_location_col].str.contains('@'), # '@'가 포함된 경우
df[p_location_col].str.split('@').str[-1], # '@' 이후의 부분을 반환
np.where(
df[p_location_col].str.contains('\\$'), # '$'가 포함된 경우
df[p_location_col].str.split('\\$').str[-1], # '$' 이후의 부분을 반환
df[p_location_col] # 둘 다 포함되지 않은 경우 원래 값 반환
)
)
return df
# 예시 DataFrame 생성
data = {'p_location': ['user@example.com', 'location$city', 'no_special_char']}
df = pd.DataFrame(data)
# 함수 적용
df = p_location_vectorized(df, 'p_location')
print(df)
'랭귀지 > pandas' 카테고리의 다른 글
splite (0) | 2025.03.13 |
---|---|
날짜 형식 변환 (YYYY-MM-DD 형식으로) (0) | 2025.03.12 |
주어진 조건에 따라 각각 100개의 행을 랜덤하게 추출하여 새로운 DataFrame을 만드는 예제 (0) | 2025.03.07 |
데이터프레임의 특정 열을 datetime으로 변환 (0) | 2025.03.04 |
두 대이타 프레임비교 (0) | 2025.02.26 |
Comments