Check for space in dataframe using isspace() function in pandas – python

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

space in a column of dataframe in python 1

 

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

space in a column of dataframe in python 2

 

previous space in a column of dataframe in python isspace() Function in pandas python                                                                                                           next space in a column of dataframe in python isspace() Function in pandas python

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts