我正在處理幾個出租車數據集。我已經使用熊貓將所有數據集連接成一個數據框。從熊貓數據框中的多行中提取非nan值
我的數據框看起來像這樣。
675 1039 #and rest 125 taxis
longitude latitude longitude latitude
date
2008-02-02 13:31:21 116.56359 40.06489 Nan Nan
2008-02-02 13:31:51 116.56486 40.06415 Nan Nan
2008-02-02 13:32:21 116.56855 40.06352 116.58243 39.6313
2008-02-02 13:32:51 116.57127 40.06324 Nan Nan
2008-02-02 13:33:21 116.57120 40.06328 116.55134 39.6313
2008-02-02 13:33:51 116.57121 40.06329 116.55126 39.6123
2008-02-02 13:34:21 Nan Nan 116.55134 39.5123
其中675,1039是出租車ID。基本上共有127輛出租車的相應的緯度和經度顯示出來。
我有幾種方法來提取行的非空值。
df.ix[k,df.columns[np.isnan(df.irow(0))!=1]]
(or)
df.irow(0)[np.isnan(df.irow(0))!=1]
(or)
df.irow(0)[np.where(df.irow(0)[df.columns].notnull())[0]]
任何上述命令將返回的,
675 longitude 116.56359
latitude 40.064890
4549 longitude 116.34642
latitude 39.96662
Name: 2008-02-02 13:31:21
現在我想提取前幾行中的所有NOTNULL值(從第1行說到行6)。
我該怎麼做?
我可以循環它。但我想要一個非循環的方式來做到這一點。
任何幫助,建議,歡迎。 謝謝! :)
非常感謝你的信息。但顯然你提到的命令不是我想要的:(:(連續,我需要提取所有notnull值。=>多行,沒有迭代,我可以以更緊湊的方式做到這一點是問題。你這麼多回復:) – user2179627