Mar-25-2021, 01:00 PM
Hello all,
I am making a program that needs to calculate the downtime of different modules of a tool.
I have already made a part of the program where it sorts one dataframe from an array with different data frames.
The problem is that I don't know how to make a loop so it processes all the dataframes in the array automatically.
Note that I used the second value of the array (DNS_8) as I was trying to make this work for only one value.
Best regards,
Tibo
I am making a program that needs to calculate the downtime of different modules of a tool.
I have already made a part of the program where it sorts one dataframe from an array with different data frames.
The problem is that I don't know how to make a loop so it processes all the dataframes in the array automatically.
Note that I used the second value of the array (DNS_8) as I was trying to make this work for only one value.
print(df['ent_name'].unique()) #making new dataframes df_array = [] for name in df['ent_name'].unique() : df_array.append(df[df.ent_name == name]) ['DNS_8-WM2' 'DNS_8' 'DNS_8-WM1' 'DNS_8-WM5' 'DNS_8-LP1' 'DNS_8-LP2' 'DNS_8-LP5' 'DNS_8-LP6' 'DNS_8-ATM1'] df_array[1] = df_array[1].reset_index(drop=True) DNS_8_Sorted = df_array[1][df_array[1]['state'].isin(['IDLE_ERROR', 'PARTLY_UP', 'UP'])] # zoek enkel naar 'IDLE_ERROR' en 'PARTLY_UP' in de kolom 'state' DNS_8_Sorted = DNS_8_Sorted[DNS_8_Sorted['state'].ne(DNS_8_Sorted['state'].shift())] # na een IDLE_ERROR wordt altijd een PARTLY_UP gezocht en andersom ook m1 = DNS_8_Sorted['state'].eq('IDLE_ERROR') & DNS_8_Sorted['state'].shift(-1).eq('PARTLY_UP' or 'UP') m2 = DNS_8_Sorted['state'].eq('PARTLY_UP' or 'UP') & DNS_8_Sorted['state'].shift().eq('IDLE_ERROR') DNS_8_Done = DNS_8_Sorted[m1 | m2] IDLE_ERROR = DNS_8_Done.iloc[::2] PARTLY_UP_OR_UP = DNS_8_Done.iloc[1::2] DNS_8_Sorted['Time_difference'] = PARTLY_UP_OR_UP['date_time_stamp'] - IDLE_ERROR['date_time_stamp'].to_numpy() DNS_8_Sorted['Time_difference'] = DNS_8_Sorted['Time_difference'].fillna(pd.Timedelta(0))I hope you understand my problem as my english is not so great.
Best regards,
Tibo