I'm trying to assign a different to different selections of index positions or timestamp objects in a large data frame. I wrote if statements to label the specific day the spikes occurred in the testing period (see below). I'd like to do something similar with the specific times the spikes occurred on those days; however, the spikes occur at different times.
day_type = [] for row in opt['date']: if row == '12/21/2020': day_type.append('Spike Day') elif row == '12/22/2020': day_type.append('Spike Day') elif row == '12/23/2020': day_type.append('Spike Day') elif row == '01/05/2021': day_type.append('Spike Day') else: day_type.append('Idle Day') opt['day_type'] = day_type I've tried defining one of the desired ranges as a variable. spike_window_5 = opt.iloc[6283:6296] And a series of objects in a column --> spike_window_5 = opt['timestamp'].loc['01/05/2021 01:13':'01/05/2021 02:18'] Spike_Window = [] if spike_window_5 in opt.index : Spike_Window.append('Spike 5') else: Spike_Window.append('Idle') opt['Spike Window'] = Spike_Window but I get the type error: 'DataFrame' objects are mutable, thus they cannot be hashed.
What can I do differently?
https://stackoverflow.com/questions/65929627/how-do-i-assign-a-name-to-range-of-values-in-the-index-or-in-a-column January 28, 2021 at 09:06AM
没有评论:
发表评论