Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
str.isalpha() method is used to check if all characters in each string in series are alphabetic(a-z/A-Z). Whitespace or any other character occurrence in the string would return false, but if there is a complete numeric value, then it would return NaN.
Return Type: Boolean series, Null values might be included too depending upon caller series.
To download the CSV used in code, click here.
In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below.
In this example, the isalpha() method is applied on the College column. Before that, the Null rows are removed using .dropna() method to avoid errors.
As shown in the output image, the bool_series can be matched with the College column and it can be clearly seen that if the string contains only alphabets, True is returned.
In this example, the isalpha() method is applied on Name column twice. First a bool series is created for the original name column, after that the white spaces are removed using str.replace() method and then a new bool_series is created again.
As shown in the output image, the Bool series was false for all values until the strings had whitespace. After removing white spaces, the bool series in only false where the string is having special characters.
- Python | pandas.to_markdown() in Pandas
- Python | pandas.map()
- Python | Pandas.CategoricalDtype()
- Python | Pandas Series.agg()
- Python | Pandas Series.all()
- Python | Pandas Series.le()
- Python | Pandas Series.ge()
- Python | Pandas dataframe.mean()
- Python | Pandas Dataframe.at[ ]
- Python | Pandas TimedeltaIndex.contains
- Python | Pandas dataframe.std()
- Python | Pandas Series.ne()
- Python | Pandas dataframe.sem()
- Python | Pandas Panel.mod()
- Get Day from date in Pandas - Python
- Python | Pandas Series.eq()
- Python | Pandas Series.min()
- Python | Pandas Series.abs()
- Python | Pandas Series.dt.second
- Python | Pandas dataframe.sum()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai