Datetimes in pandas & numpy

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.

推荐阅读更多精彩内容

  • 良师益友的书—《小说写作教程》 文/非象 我还没读完这本书,书被人翻了翻,就被人借出去了。借书人说,这样的思路有点...
    非象阅读 80评论 0 0
  • 清风将往事勾勒, 落叶将景色定格。 丛林萧索,花儿败落, 孤灯倾听影子的寂寞。 心情似大雨滂沱, 淋湿我栖息的角落...
    追摩阅读 298评论 0 3
  • 1. 胖三儿是我见过的最潮最文艺的胖子。其实胖三儿小时侯不胖,长地白白净净,文质彬彬,我和他小学一个班,班里好多女...
    張小腐阅读 305评论 2 7