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.map()
- Python | Pandas PeriodIndex.second
- Python | Pandas Index.all()
- Python | Pandas Index.any()
- Python | Pandas DataFrame.ix[ ]
- Python | Pandas Series.mod()
- Python | Pandas dataframe.pow()
- Python | Pandas Panel.mod()
- Python | Pandas.apply()
- Python | Pandas TimedeltaIndex.contains
- Python | Pandas Series.get()
- Python | Pandas Panel.add()
- Python | Pandas Panel.pow()
- Python | Pandas Panel.div()
- Python | Pandas Panel.mul()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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