为什么pd.Series没有复制时间列?

时间:2016-01-24 18:38:53

标签: python python-2.7 pandas

我正在尝试使用pd.Series来复制时间列,但它给了我一个完全不同的时间,为什么会这样,我怎样才能专门使用pd.Series函数来复制Pandas中的时间列? / p>

import numpy as np
import pandas as pd
from pandas import Series, DataFrame, Panel

# Get into data
data = pd.read_csv('someData.csv', header=0, encoding='utf-8', low_memory=False)
df = DataFrame(data)
df = df.sort(['time'], ascending=True)  # Sort by time

# Create a new df column using only df.time
df['time2'] = pd.Series(pd.to_datetime(date) for date in df['time'])
df['time3'] = df['time']

print df.head()

                 time
567     1/1/2015 0:12   
566     1/1/2015 0:14   
565     1/1/2015 0:28   
564     1/1/2015 0:30   
563     1/1/2015 0:42 

              time2  
567         2015-01-12 21:43:00   
566         2015-01-12 21:43:00   
565         2015-01-12 21:43:00   
564         2015-01-12 21:43:00   
563         2015-01-12 21:43:00   

             time3  
567  1/1/2015 0:12  
566  1/1/2015 0:14  
565  1/1/2015 0:28  
564  1/1/2015 0:30  
563  1/1/2015 0:42  

0 个答案:

没有答案