In this Section we will learn how to check for only space in a column of dataframe using isspace() function in pandas python
Let’s see with an example
Create a dataframe
## create dataframe import pandas as pd d = {'Quarters' : [' ','quarter2','quarter3','quarter4'], 'Revenue':[23400344.567,54363744.678,56789117.456,4132454.987]} df=pd.DataFrame(d) print df
The resultant dataframe will be
Check for space in column of dataframe in python
# whether only space is present in Quarters column of dataframe in Python df['Quarters_isspace'] = map(lambda x: x.isspace(), df['Quarters']) print df
isspace() Function in pandas python checks whether the string consists of only space.
It returns True when only space is present and it returns False when it does not have only space.
The result is stored in the Quarters_isspace column of the dataframe.
So the resultant dataframe will be