2017-09-01 29 views
-1

我有被組織2個的數據幀如下:熊貓合併錯誤:TIMEDATE被轉換爲UNIX

eth_price.head(n=5) 

Out[12]: 
       time eth_price 
0 2017-08-28 16:19:00 344.021 
2 2017-08-28 16:24:00 343.833 
3 2017-08-28 16:29:00 343.643 
4 2017-08-28 16:34:00 343.632 
5 2017-08-28 16:39:00 343.456 
btc_price.head(n=5) 

Out[13]: 
        time btc_price 
0 2017-08-27 22:50:00 4,389.6113 
1 2017-08-27 22:51:00 4,389.0850 
2 2017-08-27 22:52:00 4,388.8625 
3 2017-08-27 22:53:00 4,389.7888 
4 2017-08-27 22:56:00 4,389.9138 

我想用下面的代碼合併他們time

all_data = pd.merge(btc_price, eth_price, on = 'time', how = 'outer') 

一個數據幀是6195行,另一個是908.理論上,all_data應該返回6195行,包含3列(time,btc_price,eth_price)。

出於某種原因,eth_price時間戳最初的btc_price timestamp-匹配正在轉化爲UNIX在這樣合併的數據幀:

time    btc_price  eth_price 
1504304640000000000  NA   386.541 
1504304940000000000  NA   386.48 
1504305240000000000  NA   386.67199999999997 
1504305540000000000  NA   386.37199999999996 
1504305840000000000  NA   386.606 

這究竟是爲什麼以及如何解決呢?

編輯:這個問題即使仍然存在,當我使用顯式定義eth_price數據的時間戳,eth_price[0] = pd.to_datetime(eth_price[0], unit = 's')

+0

您是如何解決上一個問題的日期時間轉換問題的? –

+0

呃,實際上問題是csv文件本身的結構......行由於編輯而不匹配,所以我不得不手動重新對齊列 – zsad512

+0

@cᴏʟᴅsᴘᴇᴇᴅ'btc_price ['time']。dtype Out [8] :dtype('O') eth_price ['time']。dtype Out [9]:dtype(' zsad512

回答

0

嗯,我無法修復轉換到Unix時間戳eth_price,我也摸不清爲什麼它首先發生。

所以,我的解決方案是使用df.join代替如下:

all_data1 = btc_price.join(eth_price) 

當我運行這行代碼中,eth_price['time']柱保持其原始格式。