Fill NaN values
问题 I have a dataframe TIMESTAMP P_ACT_KW PERIODE_TARIF P_SOUSCR 2016-01-01 00:00:00 116 HC 250 2016-01-01 00:10:00 121 HC 250 2016-01-01 00:20:00 121 NaN 250 To use this dataframe, I must to fill the NaN values by (HC or HP) based on this condition: If (hour extracted from TIMESTAMP is in {0,1,2, 3, 4, 5, 22, 23} So I replace NaN by HC, else by HP. I did this function: def prep_data(data): data['PERIODE_TARIF']=np.where(data['PERIODE_TARIF']in (0, 1,2, 3, 4, 5, 22, 23),'HC','HP') return data But