1

In doing a lot of manipulations on dataframe and in one of them it can return empty (which an except able result).

the thing is if turns empty it crashes on the other line, like in the following code:

NumOfActiveDays = local_input_list.groupby(['DeviceSidID'])['timestamp'].nunique().reset_index().rename(columns={'timestamp': 'NumOfDays'})
NumOfActiveDays = NumOfActiveDays[NumOfActiveDays.NumOfDays >= float(extdf.dict[entity]['days_thresh'])]
local_input_list = local_input_list[local_input_list.DeviceSidID.isin(NumOfActiveDays.loc[:, 'DeviceSidID'])].reset_index(drop=True)

if NumOfActiveDays will become empty it will crash the third line... is there a better why to check if data manipulation ends up empty instead of after every line to do if df.empty()?

Thanks

O. San
  • 1,107
  • 3
  • 11
  • 25
  • 1
    You could use a try, except statement. http://stackoverflow.com/questions/730764/try-except-in-python-how-do-you-properly-ignore-exceptions – bluprince13 Feb 27 '17 at 13:52

0 Answers0