我正在研究几个出租车数据集。我使用 pandas 将所有数据集连接到一个数据框中。
我的数据框看起来像这样。
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
现在我想从前几行中提取所有非空值(比如从第 1 行到第 6 行)。
我怎么做?
我可能可以把它循环起来。但我想要一种非循环的方式来做到这一点。
欢迎任何帮助,建议。谢谢你的建议!:)