2016-03-04 65 views
0

我試圖將pandas DataFrame的列中的值設置爲另一個pandas DataFrame中列的值。我遇到類型(pandas.tslib.Timestamp)未正確轉換的問題。在pandas列中設置日期時間值:類型不能正確轉換

我有一個數據幀indicators

      0 
        Timestamp 
0 2016-02-12 13:45:00-05:00 
1 2016-02-16 13:45:00-05:00 
2 2016-02-17 13:45:00-05:00 
3 2016-02-18 13:45:00-05:00 
4 2016-02-19 13:45:00-05:00 
5 2016-02-22 13:45:00-05:00 
6 2016-02-24 13:45:00-05:00 
7 2016-02-25 13:45:00-05:00 
8 2016-02-26 13:45:00-05:00 
9 2016-02-29 13:45:00-05:00 
10 2016-03-01 13:45:00-05:00 
11 2016-03-02 13:45:00-05:00 
12 2016-03-03 13:45:00-05:00 

而另一數據框signals

 Signal Timestamp 
0 0  NaN  NaN 
    1  NaN  NaN 
    2  NaN  NaN 
    3  NaN  NaN 
    4  NaN  NaN 
    5  NaN  NaN 
    6  NaN  NaN 
    7  NaN  NaN 
    8  NaN  NaN 
    9  NaN  NaN 
    10 NaN  NaN 
    11 NaN  NaN 
    12 NaN  NaN 

signals.info()

<class 'pandas.core.frame.DataFrame'> 
MultiIndex: 19500 entries, (0, 0) to (1499, 12) 
Data columns (total 2 columns): 
Signal  0 non-null object 
Timestamp 0 non-null object 
dtypes: object(2) 
memory usage: 457.0+ KB 

我嘗試這樣做:

signals['Timestamp'][0] = indicators[0]['Timestamp'] 

產生

 Signal   Timestamp 
0 0  NaN 1455302700000000000 
    1  NaN 1455648300000000000 
    2  NaN 1455734700000000000 
    3  NaN 1455821100000000000 
    4  NaN 1455907500000000000 
    5  NaN 1456166700000000000 
    6  NaN 1456339500000000000 
    7  NaN 1456425900000000000 
    8  NaN 1456512300000000000 
    9  NaN 1456771500000000000 
    10 NaN 1456857900000000000 
    11 NaN 1456944300000000000 
    12 NaN 1457030700000000000 

我如何得到這個正確轉換?

+0

你是什麼蟒蛇,numpy的和熊貓的版本? – EdChum

+0

Python是'3.4.4',熊貓'0.17.1',numpy是'1.11.0b2' – baconwichsand

+0

OK,'signals.info()'顯示什麼? – EdChum

回答

0

我落得這樣做

signals['Timestamp'][0] = indicators[0]['Timestamp'].set_index('Timestamp').index 
相關問題