mercredi 5 août 2015

If test on DataFrame that excludes first column

I have the following DataFrame:

raw_data_4iftest=
                                                      Time        F1         F2  
2082-05-03 00:00:59.961599999 2082-05-03 00:00:59.961599999  -83.820000  29.430000      
2082-05-03 00:02:00.009600000 2082-05-03 00:02:00.009600000  -84.330002  28.940001   
2082-05-03 00:02:59.971200000 2082-05-03 00:02:59.971200000  -84.660004  27.940001   
2082-05-03 00:04:00.019200000 2082-05-03 00:04:00.019200000  -84.699997  -84.69999

         dtype='datetime64[ns]', length=1440, freq=None, tz=None)

I would like to run an if-test on this DataFrame that excludes the 'Time' column - i.e. something along the lines of:

if (*cells*) in raw_data_4iftest !='datetime64[ns]'    # if cell is **not** a datetime64 object
    raw_data_iftest = raw_data_4iftest >= 0.05
    raw_data_iftest_num = raw_data_iftest.astype(int)

So that raw_data_iftest_num returns:

raw_data_iftest_num=
                                                      Time  F1 F2  
2082-05-03 00:00:59.961599999 2082-05-03 00:00:59.961599999  0  1      
2082-05-03 00:02:00.009600000 2082-05-03 00:02:00.009600000  0  1   
2082-05-03 00:02:59.971200000 2082-05-03 00:02:59.971200000  0  1

Currently, I'm just doing the following:

raw_data_iftest = raw_data_4iftest >= 0.05
raw_data_iftest_num = raw_data_iftest.astype(int)

but this gives the output below, which doesn't allow me to perform the manipulations I need to to raw_data_iftest_num later in my code:

raw_data_iftest_num =

                                  Time  F1 F2  
    2082-05-03 00:00:59.961599999    1  0  1      
    2082-05-03 00:02:00.009600000    1  0  1   
    2082-05-03 00:02:59.971200000    1  0  1

I'm pretty new to programming in Python (and using Pandas) so any help/input would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire