pandas str replace tool

Smiling Sammy·2022년 5월 30일
0

Python

목록 보기
6/6

문제

pandas 툴을 사용해 replace('__', ',') 작업을 진행했는데 데이터가 변환되지 않았다.

시도
1. type문제인가 싶어서 다시 str type으로 바꾸고 진행 (실패)
df.astype(str).replace('__', ',')
2. 바꾸려는 문자열 '__' 가 데이터에도 더블언더스코어로 적혀있는지 확인 (동일했음)

방법

pandas substring을 바꾸는 방법으로 아래와 같은 방법이 존재했다.

df.Series.str.replace

코드로 적용해보면 아래와 같다.
df[바꾸려는 column].str.replace('__', ',')

참고

profile
Data Scientist, Data Analyst

0개의 댓글