dataframe을 . (콤마)로 handling 가능 하다.
After you’ve loaded the data into the DataFrame, you can quickly query the whole pandas column to filter for entries that contain a substring:
>>> companies[companies.slogan.str.contains("secret")]
company slogan
7 Maggio LLC target secret niches
117 Kub and Sons brand secret methodologies
654 Koss-Zulauf syndicate secret paradigms
656 Bernier-Kihn secretly synthesize back-end bandwidth
921 Ward-Shields embrace secret e-commerce
945 Williamson Group unleash secret action-items
You can use .str.contains() on a pandas column and pass it the substring as an argument to filter for rows that contain the substring.
Note: The indexing operator ([]) and attribute operator (.) offer intuitive ways of getting a single column or slice of a DataFrame.
However, if you’re working with production code that’s concerned with performance, pandas recommends using the optimized data access methods for indexing and selecting data.
When you’re working with .str.contains() and you need more complex match scenarios, you can also use regular expressions! You just need to pass a regex-compliant search pattern as the substring argument:
>>> companies[companies.slogan.str.contains(r"secret\w+")]
company slogan
656 Bernier-Kihn secretly synthesize back-end bandwidth
출처:
https://realpython.com/python-string-contains-substring/
How to Check if a Python String Contains a Substring – Real Python
In this tutorial, you'll learn the best way to check whether a Python string contains a substring. You'll also learn about idiomatic ways to inspect the substring further, match substrings with conditions using regular expressions, and search for substring
realpython.com
'Python' 카테고리의 다른 글
Python 가상환경 특정 version 설치하기 (2) | 2024.12.28 |
---|---|
python 무료 강의 (2) | 2023.03.28 |
python winsound beep 소리 내기 (4) | 2023.02.04 |
크롤링 checkbox 선택 및 해제 확인 하기 (2) | 2023.02.02 |
Python selenium element finding ways (2) | 2023.01.25 |
댓글