我在this excercising上打開數據集。使用dataframes的基本描述:熊貓/ Python數據框 - 在合併邏輯中丟失
有一個包含數據的可得信息:dataavail
Timestamp Availability
201605252300 True
201605252315 False
201605252015 True
有一個包含實際數據weatherdata
SquareID Timestamp Precipitation
25 201605252300 1
的事情是,如果有是否雨,即不是標記爲weatherdata.Precipitation
爲0
,而是由s暗示從weatherdata
丟失。然而,並非所有丟失的數據都不意味着沒有降水,這也意味着技術失敗。這就是dataavail
的地方。如果Timestamp
在data
Availability
是False
,這意味着有技術問題,並且沒有數據。如果在data
一個Timestamp
的Availability
是True
,這意味着沉澱竟是0
我想,讓我有一個描述的選項的完整頻譜,即一個看起來像這樣的數據幀這兩個dataframes結合:
Timestamp Availability Precipitation
201605252300 True 1 #if the availability is True, and there's rain, data can be pulled from weatherdata
201605252315 False NaN #if there's a technical issue, data can stay NaN for further imputation
201605252015 True 0 #if the data's availability is True, but there's no entry fot it in weatherdata, it should be 0
我們做到這一點,我想將它們合併爲
precip_alldata = pd.merge(weatherdata, dataavail, on=['Timestamp'], how='right')
在我的理解,根據documentation這應該
權:只使用按鍵從右框架(SQL:右外連接)
但是,這是我想要的,因爲在dataavail
有一個爲所有可能的時間戳可用性數據。我也明白,如果可用性爲真,這還不能用NaN取代NaN。但是,輸出precip_alldata
沒有任何行,其中Availability
是True
,但Precipitation
是NaN
,這使我相信某些事情在我的想法中不存在。看看原始數據集,我可以清楚地看到沒有降水的場合,Avaiability
爲True
。所以,我的輸出看起來像
Timestamp Availability Precipitation
201605252300 True 1
201605252315 False Nan
凡在我的理解/我要的是
Timestamp Availability Precipitation
201605252300 True 1
201605252315 False NaN
201605252015 True NaN
在這第一步
。 請您指出我思想中的罪魁禍首嗎?謝謝!
做任何事情的變化,當你做對'= [ '時間戳', '沉澱']'合併? – Khris
@Khris - 由於這兩個數據集中都不存在降水,因此這將不起作用。 –