str.isalpha() is used to check if all characters on each line, the series are alphabetic (az / AZ). Space or any other character occurrence in the string will return false, but if there is a full numeric value, then NaN will be returned.
Syntax: Series.str.isalpha ()
Return Type: Boolean series, Null values might be included too depending upon caller series.
To load the CSV used in the code, click here.
In the following examples, the data frame used contains data for some NBA players. An image of the data frame before any operations is attached below.
Example # 1:
In this example the isalpha () method is applied to the College column. Before that, null lines are removed using the .dropna () method to avoid errors.
As shown in the output image, bool_series can be matched against the College column and you can clearly see that if the string contains alphabets only, True is returned.
Example # 2:
In this example the isalpha () method is applied to the Name column twice. First, a bool series is created for the original name column, and then the spaces are removed using the str.replace (), and then a new bool_series is created again.
As shown in the output image, the Bool series was false for all values as long as the lines had no spaces. After removing spaces in the string, bool is only specified false if there are special characters in the string.