pandas - python: slice according to an irregular pattern -
below, can find excerpt pandas timeseries. slice rows set apart white space. there recurring pattern, i.e. 21 times value x, 4 different values abcd, 21 times value y, 4 different values efgh, 21 times value z etc. in case, i'm interested in obtaining bcdy, fghz , on.
the problem pattern interrupted due missing data.
any ideas? thanks.
2014-01-20 00:00:00 197021 2014-01-20 00:01:00 197021 2014-01-20 00:02:00 197021 2014-01-20 00:03:00 197021 2014-01-20 00:04:00 197021 2014-01-20 00:05:00 197021 2014-01-20 00:06:00 197021 2014-01-20 00:07:00 197021 2014-01-20 00:08:00 197021 2014-01-20 00:09:00 197021 2014-01-20 00:10:00 197021 2014-01-20 00:11:00 197021 2014-01-20 00:12:00 197021 2014-01-20 00:13:00 197021 2014-01-20 00:14:00 197021 2014-01-20 00:15:00 197021 2014-01-20 00:16:00 196836 2014-01-20 00:17:00 196865 2014-01-20 00:18:00 196787 2014-01-20 00:19:00 196915 2014-01-20 00:20:00 196902 2014-01-20 00:21:00 196902 2014-01-20 00:22:00 196902 2014-01-20 00:23:00 196902 2014-01-20 00:24:00 196902 2014-01-20 00:25:00 196902 2014-01-20 00:26:00 196902 2014-01-20 00:27:00 196902 2014-01-20 00:28:00 196902 2014-01-20 00:29:00 196902
can not iterate though lines, adding current group's list of lines, , on empty line, change list you're appending too? assumes missing data not return empty string on not creating new line.
x = 1 groups = { 1 : [], 2 : [], 3 : [] } line in file_obj.readlines(): if line: groups[x].append(line) else: x += 1 if x > 3: x = 0
Comments
Post a Comment