在插入新列时,Pandas正在将datetime列表覆盖到timestamp中

2024-09-30 05:31:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个要添加到panda中的列的datetime值列表。但是,每当我将其添加为列时,值都会更改为time stamp类型。如何获取它,以便将该列及其值保留为datetime类型?你知道吗

Code: 
#partialDates is a datetime list
#partialddf is a panda dataframe

print 'Type as an independent list:'
print type(partialDates[0]) 
partialddf['A'] = partialDates
print 'Type once inside panda as a colum:'
print type(partialddf['A'].tolist()[0])





Output:
Type as an independent list:
<type 'datetime.datetime'>
Type once inside panda as a colum:
<class 'pandas._libs.tslib.Timestamp'>

Tags: an类型datetimeisastypepandalist

热门问题