I Want To Iterate Through An Xlsx, Using Pandas, Containing Timestamps And Get Downtime
So I have an excel file with date in the first column and a regular interval timestamps in the consecutive rows and a column in the end containing the average. If the average is be
Solution 1:
moved calculation into dictionaries, as i could not find a suitable solution via Pandas.
#convert to dictionary
A = df.set_index('Date').to_dict('index')
#remove values where 'Average' is less than 100
B = {key:value for key,value in A.items() if value['Average'] < 100}
#get rid of the 'Average' key
#it is not relevant to the solution
for value in B.values():
del value['Average']
from collections import Counter,defaultdict
d=defaultdict(list)
#count the number of 0s
#if it is greater than one, keep
#and append to the defaultdict d
for key,value in B.items():
m = Counter(value.values())
M = list(value.values())
#check for consecutive 0s in list
test_for_consecutive_0 = any(i==j==0 for i,j in zip(M,M[1:]))
if test_for_consecutive_0 and (m[0]>1):
d[key].extend([key for key,val in value.items() if val==0])
#join the values into a string
result = {key:'-'.join(value) for key,value in d.items()}
print(result)
{'2-10-18': 'Timestamp2-TImestamps3',
'3-10-18': 'Timestamp2-TImestamps3-Timestamp4'}
Post a Comment for "I Want To Iterate Through An Xlsx, Using Pandas, Containing Timestamps And Get Downtime"