我正在尝试将pandas DataFrame列中的值设置为另一个pandas DataFrame中列的值。我遇到了类型(pandas.tslib.Timestamp
)无法正确转换的问题。
我有一个DataFrame 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
另一个DataFrame 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 :(得分:0)
我最终做了
signals['Timestamp'][0] = indicators[0]['Timestamp'].set_index('Timestamp').index