I am bit stuck with the code to extract the condition that I want.
What I want to do is that I want to filter the largest value of Tag AB0150 and based on that number date then I want to filter the data with that number.
Here is the example of my data. I have 3months of data and about 31 different tags.
ID TIME Machine_NO TAG VALUE
99959 2020-11-13 19:34:00 409301 AB0150 63.59
99959 2020-12-15 17:55:00 409302 AB0151 0.00
99959 2020-11-05 01:25:00 409303 AB0152 499.65
99959 2021-01-01 00:05:00 409301 AB0153 80.00
99959 2020-11-13 19:34:00 409301 AB0150 50.59
99959 2020-11-13 19:34:00 409301 AB0150 53.59
99959 2020-12-13 19:59:00 409301 AB0150 12.5
99959 2021-01-11 15:22:00 409301 AB0150 21.3
99959 2020-12-15 17:55:00 409302 AB0151 4.69
99959 2020-11-21 05:16:00 409303 AB0152 2133
99959 2020-11-13 19:34:00 409301 AB0151 700
99959 2020-11-13 19:34:00 409302 AB0152 35.5
99959 2020-11-13 19:34:00 409303 AB0153 2159
Below is the code so far.
df.sort_values(by=['TAG','VALUE'], ascending=False).drop_duplicates(subset=['TAG'],keep='first')
df_check=df[df['TIME']=='2020-11-13 19:34:00']
I want some automated code, with the code I've got I need to change the date if I change the date range.
I want to filter the largest tag and select date and extract the data with that date at once.
Is there any good way to do this?
Here is the desired output.
ID TIME Machine_NO TAG VALUE
99959 2020-11-13 19:34:00 409301 AB0150 63.59
99959 2020-11-13 19:34:00 409301 AB0151 700
99959 2020-11-13 19:34:00 409302 AB0152 35.5
99959 2020-11-13 19:34:00 409303 AB0153 2159
Thank you
question from:
https://stackoverflow.com/questions/65947038/how-to-filter-one-condition-and-extract-the-data-based-on-the-filtered-condition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…