
- Python Pandas - Home
- Python Pandas - Introduction
- Python Pandas - Environment Setup
- Python Pandas - Basics
- Python Pandas - Introduction to Data Structures
- Python Pandas - Index Objects
- Python Pandas - Panel
- Python Pandas - Basic Functionality
- Python Pandas - Indexing & Selecting Data
- Python Pandas - Series
- Python Pandas - Series
- Python Pandas - Slicing a Series Object
- Python Pandas - Attributes of a Series Object
- Python Pandas - Arithmetic Operations on Series Object
- Python Pandas - Converting Series to Other Objects
- Python Pandas - DataFrame
- Python Pandas - DataFrame
- Python Pandas - Accessing DataFrame
- Python Pandas - Slicing a DataFrame Object
- Python Pandas - Modifying DataFrame
- Python Pandas - Removing Rows from a DataFrame
- Python Pandas - Arithmetic Operations on DataFrame
- Python Pandas - IO Tools
- Python Pandas - IO Tools
- Python Pandas - Working with CSV Format
- Python Pandas - Reading & Writing JSON Files
- Python Pandas - Reading Data from an Excel File
- Python Pandas - Writing Data to Excel Files
- Python Pandas - Working with HTML Data
- Python Pandas - Clipboard
- Python Pandas - Working with HDF5 Format
- Python Pandas - Comparison with SQL
- Python Pandas - Data Handling
- Python Pandas - Sorting
- Python Pandas - Reindexing
- Python Pandas - Iteration
- Python Pandas - Concatenation
- Python Pandas - Statistical Functions
- Python Pandas - Descriptive Statistics
- Python Pandas - Working with Text Data
- Python Pandas - Function Application
- Python Pandas - Options & Customization
- Python Pandas - Window Functions
- Python Pandas - Aggregations
- Python Pandas - Merging/Joining
- Python Pandas - MultiIndex
- Python Pandas - Basics of MultiIndex
- Python Pandas - Indexing with MultiIndex
- Python Pandas - Advanced Reindexing with MultiIndex
- Python Pandas - Renaming MultiIndex Labels
- Python Pandas - Sorting a MultiIndex
- Python Pandas - Binary Operations
- Python Pandas - Binary Comparison Operations
- Python Pandas - Boolean Indexing
- Python Pandas - Boolean Masking
- Python Pandas - Data Reshaping & Pivoting
- Python Pandas - Pivoting
- Python Pandas - Stacking & Unstacking
- Python Pandas - Melting
- Python Pandas - Computing Dummy Variables
- Python Pandas - Categorical Data
- Python Pandas - Categorical Data
- Python Pandas - Ordering & Sorting Categorical Data
- Python Pandas - Comparing Categorical Data
- Python Pandas - Handling Missing Data
- Python Pandas - Missing Data
- Python Pandas - Filling Missing Data
- Python Pandas - Interpolation of Missing Values
- Python Pandas - Dropping Missing Data
- Python Pandas - Calculations with Missing Data
- Python Pandas - Handling Duplicates
- Python Pandas - Duplicated Data
- Python Pandas - Counting & Retrieving Unique Elements
- Python Pandas - Duplicated Labels
- Python Pandas - Grouping & Aggregation
- Python Pandas - GroupBy
- Python Pandas - Time-series Data
- Python Pandas - Date Functionality
- Python Pandas - Timedelta
- Python Pandas - Sparse Data Structures
- Python Pandas - Sparse Data
- Python Pandas - Visualization
- Python Pandas - Visualization
- Python Pandas - Additional Concepts
- Python Pandas - Caveats & Gotchas
Pandas Series.str.fullmatch() Method
TheSeries.str.fullmatch() method in Pandas is used to determine if each string in the Series entirely matches a specified regular expression pattern or not.
This method is useful when you want to verify if entire strings conform to a given format or pattern. And equivalent to applyingre.fullmatch() to each string in the Series.
Syntax
Following is the syntax of the PandasSeries.str.fullmatch() method −
Series.str.fullmatch(pat, case=True, flags=0, na=None)
Parameters
TheSeries.str.fullmatch() method accepts the following parameters −
pat − A string representing the character sequence or regular expression pattern to match against.
case − A boolean value, default is True. If True, the match is case sensitive.
flags − An optional integer, default is 0. Flags from the re module, such as re.IGNORECASE, to modify the pattern matching behavior.
na − An optional scalar value used for missing values. If not specified, the default depends on the dtype of the Series. For object-dtype, numpy.nan is used. For StringDtype, pandas.NA is used.
Return Value
TheSeries.str.fullmatch() method returns a Series or Index of boolean values. Each boolean value indicates whether the corresponding string in the Series entirely matches the given regular expression pattern.
Example 1
This example demonstrates checking if each string in a Series fully matches the regular expression pattern for a valid email address.
import pandas as pd# Create a Series of stringss = pd.Series(['user@example.com', 'user@domain', 'example.com', 'test@tutorialspoint.com'])# Check if each string fully matches the pattern for an email addressresult = s.str.fullmatch(r'\w+@\w+\.\w+')print("Input Series:")print(s)print("\nFull Match Results:")print(result)When we run the above code, it produces the following output −
Input Series:0 user@example.com1 user@domain2 example.com3 test@tutorialspoint.comdtype: objectFull Match Results:0 True1 False2 False3 Truedtype: bool
The output shows that only the strings that fully match the email pattern are marked asTrue.
Example 2
This example demonstrates checking if each string fully matches the pattern for a date in the format 'YYYY-MM-DD' using theSeries.str.fullmatch() method.
import pandas as pd# Create a Series of stringss = pd.Series(['2024-07-29', '2024-07-29 00:00:00', '2024-07-29T00:00:00', '07-29-2024'])# Check if each string fully matches the date patternresult = s.str.fullmatch(r'\d{4}-\d{2}-\d{2}')print("Input Series:")print(s)print("\nFull Match Results:")print(result)When we run the above code, it produces the following output −
Input Series:0 2024-07-291 2024-07-29 00:00:002 2024-07-29T00:00:003 07-29-2024dtype: objectFull Match Results:0 True1 False2 False3 Falsedtype: bool
Example 3
This example demonstrates checking if each string in a DataFrame column fully matches a date pattern, while handling missing values.
import pandas as pd# Create a DataFrame with date stringsdf = pd.DataFrame({ 'date': ['2024-07-29', '2024-07-29 00:00:00', '2024-07-29', None]})# Check if each string fully matches the date pattern, treating NaNs as Trueresult = df['date'].str.fullmatch(r'\d{4}-\d{2}-\d{2}', na=True)print("Input DataFrame:")print(df)print("\nFull Match Results:")print(result)When we run the above code, it produces the following output −
Input DataFrame: date0 2024-07-291 2024-07-29 00:00:002 2024-07-293 NoneFull Match Results:0 True1 False2 True3 TrueName: date, dtype: bool
In this case, theNaN value is treated asTrue due to thena=True parameter, while other strings are matched according to the pattern.