Last active
January 25, 2019 11:48
-
-
Save muthugit/5b0827cc210344c1cf3b8be1889d29da to your computer and use it in GitHub Desktop.
replace empty cells in dataframe using lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "MUTHUPANDIAN" | |
__email__ = "[email protected]" | |
''' | |
TO REMOVE THE NONE DATATYPE FROM THE EMPTY CELLS | |
'''' | |
# IMPORTING LIBRARIES | |
import pandas as pd | |
# READ EXCEL FILE AND LOAD TO A PANDAS DATAFRAME | |
df = pd.read_excel(<FILEPATH>) | |
# REPLACE ALL EMPTY CELLS USING LAMBDA EXPRESSION | |
df = df.apply(lambda x: x.fillna(0) if x.dtype.kind in 'biufc' else x.fillna('0')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment