Tôi đang cố gắng để tạo ra một cột dataframe Pandas mới với ngày thứ từ một cột datetime:Pandas datetime cột thứ
import pandas as pd
from datetime import datetime
print df.ix[0:5]
date
file
gom3_197801.nc 2011-02-16 00:00:00
gom3_197802.nc 2011-02-16 00:00:00
gom3_197803.nc 2011-02-15 00:00:00
gom3_197804.nc 2011-02-17 00:00:00
gom3_197805.nc 2011-11-14 00:00:00
df['date'][0].toordinal()
Out[6]:
734184
df['date'].toordinal()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-dbfd5e8b60f0> in <module>()
----> 1 df['date'].toordinal()
AttributeError: 'Series' object has no attribute 'toordinal'
Tôi đoán đây là một câu hỏi cơ bản, nhưng tôi đã phải vật lộn đọc tài liệu cho 30 phút trước.
Làm cách nào để tạo cột thời gian thứ tự cho khung dữ liệu của tôi?
Ngay, 'df [ 'ngày'] áp dụng (datetime.toordinal)' – Zero