How to customize a function to act on every value of dataframe

def hour_exceed (df):

i=df.values
if i is np.nan:
    return np.nan
elif i>200:
    return 1
elif i<200:
    return 0
< H1 > dataframe < / H1 >

df15.head ()
Out [21]:

              time  1036A  1037A  1040A  1041A  1051A  1053A  1054A  \

0 2015-01-01 00:00:00 NaN
1 2015-01-01 01:00:00 NaN
2 2015-01-01 02:00:00 NaN
3 2015-01-01 03:00:00 NaN
4 2015-01-01 04:00:00 NaN NaN NaN

1057A 1062A. 2593A 2600A 2643A 2654A 2655A 2657A 2667A\
0 NaN NaN. NaN 32.0 NaN 9.09.0 3.08.0
1 NaN NaN. NaN 33.0 NaN 9.08.03.06.0
2 NaN NaN. NaN 23.0 NaN 8.08.0 2.05.0
3 NaN NaN. NaN
4 NaN NaN. NaN 52.0 NaN 7.04.0 1.06.0

2688A 2689A 2708A
09.03.0 NaN
18.02.0 NaN
211.04.0 NaN
3 NaN
46.05.0 NaN
how to define a custom function to act on each value of dataframe

Mar.22,2021

has nothing to do with how to define a function, call df.applymap () .


directly use df [df < = 200] = 0; DF [DF > 200] = 1

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e8b082-101f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e8b082-101f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?