Horje
nan vs nat pandas Code Example
count nan pandas
#Python, pandas
#Count missing values for each column of the dataframe df

df.isnull().sum()
pandas nan values in column
df['your column name'].isnull()
nan vs nat pandas
>>> import pandas as pd, datetime, numpy as np
>>> df = pd.DataFrame({'a': [datetime.datetime.now(), np.nan], 'b': [5, np.nan], 'c': [1, 2]})
>>> df
                           a    b  c
0 2019-02-17 18:06:15.231557  5.0  1
1                        NaT  NaN  2
>>> fill_dt = datetime.datetime.now()
>>> fill_value = 4
>>> dt_filled_df = df.select_dtypes('datetime').fillna(fill_dt)
>>> dt_filled_df
                           a
0 2019-02-17 18:06:15.231557
1 2019-02-17 18:06:36.040404
>>> value_filled_df = df.select_dtypes('int').fillna(fill_value)
>>> value_filled_df
   c
0  1
1  2
>>> dt_filled_df.columns = [col + '_notnull' for col in dt_filled_df]
>>> value_filled_df.columns = [col + '_notnull' for col in value_filled_df]
>>> df = df.join(value_filled_df)
>>> df = df.join(dt_filled_df)
>>> df
                           a    b  c  c_notnull                  a_notnull
0 2019-02-17 18:06:15.231557  5.0  1          1 2019-02-17 18:06:15.231557
1                        NaT  NaN  2          2 2019-02-17 18:06:36.040404




Python

Related
cv2 videowriter python not working Code Example cv2 videowriter python not working Code Example
initialize empty dictionary python Code Example initialize empty dictionary python Code Example
django form label in template Code Example django form label in template Code Example
tkinker Code Example tkinker Code Example
how to iterate over a list in python Code Example how to iterate over a list in python Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7