본문 바로가기

카테고리 없음

extract characters

반응형

extract character only

 

1)

 df['state'] = df['raw'].str.extract('([A-Z]\w{0,})', expand=True)

https://chrisalbon.com/python/data_wrangling/pandas_regex_to_create_columns/

2)

df['movie_title'] = df['movie_title'].astype(str)

#but it remove numbers in names of movies too

df['titles'] = df['movie_title'].str.extract('([a-zA-Z ]+)', expand=False).str.strip()

df['titles1'] = df['movie_title'].str.split('(', 1).str[0].str.strip()

df['titles2'] = df['movie_title'].str.replace(r'\([^)]*\)', '').str.strip()

print df

 

https://stackoverflow.com/questions/36028932/how-to-extract-specific-content-in-a-pandas-dataframe-with-a-regex

 

How to extract specific content in a pandas dataframe with a regex?

Consider the following pandas dataframe: In [114]: df['movie_title'].head() ​ Out[114]: 0 Toy Story (1995) 1 GoldenEye (1995) 2 Four Rooms (1995) 3 Get Shorty (1995) 4 Copyc...

stackoverflow.com

3) korean only

 

(r'[^ ㄱ-ㅣ가-힣]+',"")

reference:

https://jokergt.tistory.com/52

 

[Python] 정규식을 사용하여 한글만 가져오기

한글 코드 범위 ㄱ ~ ㅎ: 0x3131 ~ 0x314e ㅏ ~ ㅣ: 0x314f ~ 0x3163 가 ~ 힣: 0xac00 ~ 0xd7a3 정규식을 사용하여 한글만 가져오기 # -*- coding: utf-8 -*- import re def test(): s='韓子는 싫고, 한글은 nice..

jokergt.tistory.com

https://www.fun-coding.org/DS&AL3-4.html

 

파이썬 라이브러리 기본: 정규표현식 - 잔재미코딩

프로그래밍 연습(생각만 해보기) 다음 코드를 실행해보고, 이름 정보를 통해 남자인지, 여자인지, 기타인지(남녀 구별 불가)를 확인할 수 있는 방법 생각해보기 import openpyxl # 엑셀파일 열기 work_book = openpyxl.load_workbook('data/train.xlsx') # 현재 Active Sheet 얻기 work_sheet = work_book.active # work_sheet.rows는 해당 쉬트의 모든 행을 객체로 가

www.fun-coding.org

 

반응형