Skip to content

Instantly share code, notes, and snippets.

@muthugit
Last active January 25, 2019 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muthugit/5b0827cc210344c1cf3b8be1889d29da to your computer and use it in GitHub Desktop.
Save muthugit/5b0827cc210344c1cf3b8be1889d29da to your computer and use it in GitHub Desktop.
replace empty cells in dataframe using lambda
__author__ = "MUTHUPANDIAN"
__email__ = "contact@muthupandian.in"
'''
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