python에서 csv데이터 dataframe ==으로 좌표 추출할때
조회수 2101회
df =pd.read_csv('사업보고서 (2019.12)삼성전자연결 현금흐름표.csv', encoding = 'euc-kr')
df == '당기순이익'
C:\Users\kmw07\anaconda3\lib\site-packages\pandas\core\ops\array_ops.py:253: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
res_values = method(rvalues)
이렇게 나오구 당기순이익 셀도 False라고 표기됩니다. 왜 이렇게 되는지 알 수있을까요??
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
1 답변
-
- 앞뒤에 빈칸이 있으면,
' 당기순이익'
은'당기순이익'
과 같지 않으므로 해당 셀은False
로 리턴 됩니다.
df["(단위 : 백만원)"] = df["(단위 : 백만원)"].map(str.strip)
이렇게 코드를 작성하고 실행하니 whitespace가 사라졌더라구요 원리를 알지못하는데 코드 해석좀 부탁드려도 될까요.df["(단위 : 백만원)"] = df["(단위 : 백만원)"].map(str.strip)
은(단위 : 백만원)
컬럼만 쭉 뽑은Series
의 매 문자열 원소에str.strip
함수를 적용한다는 뜻입니다.str.strip
이 문자열 앞 뒤의 공백을 제거하주는 함수이기 때문에 문제가 해결됩니다.
- 앞뒤에 빈칸이 있으면,
댓글 입력