Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

PREVIOUS NEXT
Code Example
Python :: python order number list 
Python :: python named tuples 
Python :: anonymous function python 
Python :: flask flash The browser (or proxy) sent a request that this server could not understand. 
Python :: atoi in python code 
Python :: smtp python 
Python :: How to use Counter() Function 
Python :: pandas use dict to transform entries 
Python :: python replace list from another dictionary items 
Python :: how to add badges to github repo 
Python :: request foucus tkinter widget 
Python :: format when turning float into string 
Python :: upgrade python version windows 
Python :: os module in python 
Python :: how to do more than or less than as a condition in pythonb 
Python :: Converting 12 hour clock time to 24 hour clock time 
Python :: python - input: integer 
Python :: how to import somthing from another directory in pyhon 
Python :: python pandas how to access a column 
Python :: gamma distribution python normalized 
Python :: percentage plot of categorical variable in python woth hue 
Python :: Lambda Functions using for loop 
Python :: print file in python 
Python :: Maximum sum subarray of size ‘K’ 
Python :: how to slice list 
Python :: how to return the sum of two numbers python 
Python :: aws s3 sync boto3 
Python :: django orm 
Python :: master python 
Python :: python string length 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =