-3
"제목"과 "설명"이라는 두 개의 열이있는 데이터 프레임이 있습니다. 제목 열에는 임상 실험 테스트와 관련된 많은 제목이 있습니다. 불행하게도, 대부분의 타이틀은 같은 테스트를 반복하지만, 타이틀의 사소한 변경으로 인해 타이틀은 고유 한 것으로 표시됩니다.문자열을 파이썬의 새 문자열 또는 단어로 완전히 바꾸기
values = [('Complete blood picture', 'AB'), ('Complete BLOOD test', 'AB'), ('blood glucose', 'AB'), ('COMplete blood Profile', 'AB')]
labels = ['title', 'description']
import pandas as pd
labtest = pd.DataFrame.from_records(values, columns = labels) # Create data frame
labtest = labtest.apply(lambda x: x.astype(str).str.lower()) # Convert columns to string and lower case
labtest['title'].str.contains("blood") # Search for blood
전 :
Title Description
Complete blood test AB
COMPLETE Blood test\ AB
Blood glucose AB
Complete blood picture AB
후 :
Title Description
Blood test AB
Blood test AB
Blood test AB
Blood test AB
나는 단어 "피"를 검색하고 싶습니다 [이 내가 같이하는 데이터 프레임을하고자하는 방법이다] 그 제목이 "true"이면 "Blood test"로 전체 제목을 변경하십시오.
피씨 나는 파이썬에 익숙하지 않고 텍스트 데이터로 작업하기 때문에 "피"라는 단어를 검색하는 것으로 끝났다.
@furas, typo -> str.replace() –
예를 들어, "평균 혈당 (abg)"은 항상 전체 문자열입니까? 아니면 처음이나 마지막에 보관할 다른 텍스트가있을 수 있습니까? –
'str.replace()'를 사용하려고 했습니까? 그렇지 않다면 먼저 시도하십시오. – furas