python - Replacing NaT with Epoch in Pandas -


nat missing values appearing @ end of dataframe demonstrated below. understandably raises valueerror:

file "/system/library/frameworks/python.framework/versions/2.7/extras/lib/python/pytz/tzinfo.py", line 314, in localize loc_dt = tzinfo.normalize(dt.replace(tzinfo=tzinfo)) valueerror: month must in 1..12

i've tried use both dropna:

data[col_name].dropna(0, inplace=true) 

and fillna, encouraged working missing data section:

data[col_name].fillna(0, inplace=true) 

before either of these lines, tried clean data replacing non-datetimes epoch time:

data[col_name] = a_col.apply(lambda x: x if isinstance(x, datetime.datetime)  else epoch) 

because nat technically datetime condition wasn't covered function. since isnull handle this, wrote function apply data[col_name]:

def replace_time(x): if pd.isnull(x):     return epoch elif isinstance(x, datetime.datetime):     return x else:     return epoch 

despite fact enters pd.isnull section, value isn't changed. however, when try function on series (where second value nat) works:

s = pd.series([pd.timestamp('20130101'),np.nan,pd.timestamp('20130102 9:30')],dtype='m8[ns]') 

data:

2003-04-29 00:00:00

nat

nat

nat

try:

data[col_name] = a_col.apply(lambda x: x if isinstance(x, datetime.datetime)                                         , not isinstance(x, pd.tslib.nattype) else epoch) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -