I have a data frame in Python. This data frame has columns like id , test_time , test_id , status.
Now I want to create a function that applies on the original data frame and creates a new data frame.
Function requirements
1) For each `test_id` there will be number of timestamps. I want to group timestamps for every ten minutes from the first timestamp for that particular `test_id` and count number of timestamps for that `test_id` in that 10 minute window and insert into new data frame column called `test_count`.
2) if the `test_id` has more than 10 timestamps in the 10 minute window then assign the status as `testing on` in the new data frame.
3) if the `test_id` has more than 10 timestamps in the next 10 minute window then assign the status as `testing` in the new data frame.
4) if the `test_id` has more than 10 timestamps in the next 10 minute window then assign the status as `testing` in the new data frame.
5) if the `test_id` has less than 10 timestamps in the next 10 minute window then assign the status as `testing off` in the new data frame.
6) if the `test_id` has less than 10 timestamps in the 10 minute window then assign the status as in the old data frame in the new data frame.
Insert the data into new data frame like below.
This is an example for data in new data frame for the first test_id in the dataset
id test_time test_id STATUS test_count
1 2016-07-27 15:02:25.898 1040 testing on 100
Dataset:
id test_time test_id STATUS
2000 2016-01-27 14:52:25.898 1040 testing off
2001 2016-01-27 14:52:25.898 1050 testing on
2003 2016-01-27 14:59:25.776 1040 testing on
2004 2016-01-27 14:59:25.776 1050 testing off
2006 2016-01-28 11:42:40.173 1040 testing off
2007 2016-01-28 11:42:40.173 1050 testing on
2009 2016-01-28 11:51:06.731 1040 testing on
2010 2016-01-28 11:51:06.731 1050 testing off
2012 2016-01-28 12:00:00.009 1064 testing on
2013 2016-01-28 12:00:00.009 1066 testing on
2015 2016-01-28 12:02:00.009 294 testing on
2016 2016-01-28 12:02:26.769 294 testing off
2017 2016-01-28 12:02:21.189 1093 testing on
2018 2016-01-28 12:02:23.209 1093 testing off
2019 2016-01-28 12:02:00.009 1094 testing on
2020 2016-01-28 12:02:26.769 1094 testing off
2021 2016-01-28 12:02:20.029 1062 testing off
2022 2016-01-28 12:02:00.029 1062 testing on
2023 2016-01-28 12:03:37.109 1063 testing on
2024 2016-01-28 12:03:57.109 1063 testing off
2025 2016-01-28 12:03:37.109 1064 testing off
2026 2016-01-28 12:02:00.029 1064 testing off
2027 2016-01-28 12:02:26.769 1064 testing on
2028 2016-01-28 12:03:07.089 1065 testing on
2029 2016-01-28 12:03:37.469 1065 testing off
2030 2016-01-28 12:03:37.109 1066 testing off
2031 2016-01-28 12:02:00.029 1066 testing off
2032 2016-01-28 12:02:26.769 1066 testing on
2033 2016-01-28 12:02:25.509 1105 testing on
2034 2016-01-28 12:02:25.889 1105 testing off
2035 2016-01-28 12:02:28.549 1105 testing off
2036 2016-01-28 12:02:25.529 1105 testing off
2037 2016-01-28 12:02:25.909 1105 testing on
2038 2016-01-28 12:02:25.549 1105 testing on
2039 2016-01-28 12:02:25.929 1105 testing off
2040 2016-01-28 12:02:25.569 1105 testing off
2041 2016-01-28 12:02:25.949 1105 testing on
2042 2016-01-28 12:02:25.589 1105 testing on
2043 2016-01-28 12:02:25.969 1105 testing off
2044 2016-01-28 12:02:25.609 1105 testing off
2045 2016-01-28 12:02:25.989 1105 testing on
2046 2016-01-28 12:02:25.629 1105 testing on
2047 2016-01-28 12:02:26.009 1105 testing off
2048 2016-01-28 12:02:25.649 1105 testing off
2049 2016-01-28 12:02:26.029 1105 testing on
2050 2016-01-28 12:02:25.669 1105 testing on
2051 2016-01-28 12:02:26.049 1105 testing off
2052 2016-01-28 12:02:25.689 1105 testing off
2053 2016-01-28 12:02:26.069 1105 testing on
2054 2016-01-28 12:02:25.709 1105 testing on
2055 2016-01-28 12:02:26.089 1105 testing off
2056 2016-01-28 12:02:25.729 1105 testing off
2057 2016-01-28 12:02:26.109 1105 testing on
2058 2016-01-28 12:02:25.749 1105 testing on
2059 2016-01-28 12:02:26.129 1105 testing off
2060 2016-01-28 12:02:25.769 1105 testing off
2061 2016-01-28 12:02:26.149 1105 testing on
2062 2016-01-28 12:02:25.789 1105 testing on
2063 2016-01-28 12:02:26.169 1105 testing off
2064 2016-01-28 12:02:25.809 1105 testing off
2065 2016-01-28 12:02:26.189 1105 testing on
2066 2016-01-28 12:02:25.829 1105 testing on
2067 2016-01-28 12:02:26.209 1105 testing off
2068 2016-01-28 12:02:25.849 1105 testing off
2069 2016-01-28 12:02:26.229 1105 testing on
2070 2016-01-28 12:02:25.869 1105 testing on
2071 2016-01-28 12:02:26.249 1105 testing off
2072 2016-01-28 12:02:26.269 1105 testing on
2073 2016-01-28 12:02:26.289 1105 testing off
2074 2016-01-28 12:02:26.309 1105 testing on
2075 2016-01-28 12:02:26.329 1105 testing off
2076 2016-01-28 12:02:26.349 1105 testing on
2077 2016-01-28 12:02:26.369 1105 testing off
2078 2016-01-28 12:02:26.389 1105 testing on
2079 2016-01-28 12:02:26.409 1105 testing off
2080 2016-01-28 12:02:26.429 1105 testing on
2081 2016-01-28 12:02:26.449 1105 testing off
2082 2016-01-28 12:02:26.469 1105 testing on
2083 2016-01-28 12:02:26.489 1105 testing off
2084 2016-01-28 12:02:26.509 1105 testing on
2085 2016-01-28 12:02:26.529 1105 testing off
2086 2016-01-28 12:02:26.549 1105 testing on
2142 2016-01-28 12:30:23.543 1040 testing off
2143 2016-01-28 12:30:23.543 1050 testing on
2145 2016-01-28 12:34:57.442 1040 testing on
2146 2016-01-28 12:34:57.442 1050 testing off
2148 2016-01-28 12:42:18.201 1040 testing off
2149 2016-01-28 12:42:18.201 1050 testing on
2151 2016-01-28 12:59:26.657 1040 testing on
2152 2016-01-28 12:59:26.657 1050 testing off
2154 2016-01-28 13:04:38.957 1040 testing off
2155 2016-01-28 13:04:38.957 1050 testing on
2157 2016-01-28 14:27:41.619 1040 testing on
2158 2016-01-28 14:27:41.619 1050 testing off
2160 2016-01-28 14:34:13.478 1040 testing off
2161 2016-01-28 14:34:13.478 1050 testing on
2163 2016-01-28 16:58:13.329 1040 testing on
2164 2016-01-28 16:58:13.329 1050 testing off
2166 2016-01-29 01:17:13.145 943 testing off
How can I achieve that?
I am new to python so please try to give explanation with answers
Thank you
Aucun commentaire:
Enregistrer un commentaire