美文网首页
Datetimes in pandas & numpy

Datetimes in pandas & numpy

作者: mkrriver | 来源:发表于2017-04-26 17:25 被阅读0次

Reading files with datetime type data

pd.read_csv(path, parse_dates=['columnname'],infer_datetime_format=True,date_parser=parser_func)
Does not work when NaN values are included.
Example of a parser function:
parser = lambda x: datetime.strptime(x,'%d %b %Y %I:%M:%S.%f')
Remember to import datetime from datetime, datetime class inside datetime module

Workaround when NaN values exist:

df = pd.read_csv(file)
df.dropna(axis=0, how='any',inplace=True)
df.datestamp = pd.to_datetime(df.datestamp,format='%d %b %Y %I:%M:%S.%f')

By using df.datestamp.dt, you can access attributes of the Datetime class.

相关文章

网友评论

      本文标题:Datetimes in pandas & numpy

      本文链接:https://www.haomeiwen.com/subject/umqwzttx.html