<p>在Python中,日期时间通常表示为<a href="https://docs.python.org/2/library/datetime.html#datetime-objects" rel="nofollow">datetime.datetime</a>对象。这些不是很有效,这就是Pandas使用时间戳的原因,时间戳是数字的。在</p>
<p>要读取数据(请注意<code>parse_dates</code>参数前后的双括号):</p>
<pre><code>df = pd.read_csv(filename, parse_dates=[['TranDate', 'TranTime']])
>>> df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 18 entries, 0 to 17
Data columns (total 3 columns):
TranDate_TranTime 18 non-null datetime64[ns]
TranID 18 non-null object
TranAmt 18 non-null float64
dtypes: datetime64[ns](1), float64(1), object(1)
>>> df.head()
TranDate_TranTime TranID TranAmt
0 2016-04-27 02:18:00 A123456 9999.53
1 2016-04-26 02:48:00 B123457 26070.33
2 2016-04-25 03:18:00 C123458 13779.56
3 2016-04-24 03:18:00 A123459 18157.26
4 2016-04-23 04:18:00 B123460 215868.15
</code></pre>
<p>日期和时间列仅联接到一列。一旦您有了这个时间戳,就很容易使用<code>dt</code>访问器访问它的属性,例如</p>
^{pr2}$
<p>有关Pandas<a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html" rel="nofollow">date functionality</a>的更多信息,请参阅Pandas文档。在</p>