I am working on several datasets for taxis. I used pandas to combine the entire data set into a single data frame.
My dataframe looks something like this.
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
where 675,1039 are taxi identifiers. Basically, a total of 127 taxis with corresponding latitudes and longitudes are broken up in columns.
I have several ways to extract non-zero values for a string.
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]]
any of the above commands will return,
675 longitude 116.56359
latitude 40.064890
4549 longitude 116.34642
latitude 39.96662
Name: 2008-02-02 13:31:21
now I want to extract all the notnull values from the first few lines (for example, from line 1 to line 6).
how to do it?
I might loop it. But I want him not to go in cycles.
Any help, suggestions are welcome. Thanks in adv! :)
source