On Tue, Jun 19, 2018 at 2:29 PM, Rich Shepard <[email protected]> wrote:
> On Tue, 19 Jun 2018, Robert Citek wrote:
>
>> I don't fully understand your question, but here are some examples
>> that may be a step in the right direction:
>
>
> Robert,
>
> I did not provide as complete an explanation as I should have.
>
> Each file has 8761 lines, one for each hour of each day during the
> (non-leap) year, plus a header line. It's not just two isolated lines,
> unfortunately.
>
> I don't follow the logic of your two examples for finding only the
> duplicate 16:00 hours in each day, and changing only the second instance to
> 17:00.
>
>> $ seq 1 5 | sed -e '1~2s/$/ --/'
>> 1 --
>> 2
>> 3 --
>> 4
>> 5 --
>>
>> $ seq 1 5 | sed -e '0~2s/$/ --/'
>> 1
>> 2 --
>> 3
>> 4 --
>> 5
>
>
> Perhaps I need to write a python script that looks for the string, 16:00,
> and sets a flag the first time that's found. The next time it's found, in
> the following row, the flag is set so the string is changed to 17:00 and the
> flag is unset. Then the script keeps reading until it encounters the next
> day's 16:00 row.
>
Python will be the easiest to understand.
is it always 16:00, or is it any time the whole line is duplicated,
bump the 2nds hour?
also, if you have one line for every hour of the year, how about
looping over all those datetimes, pared up with your data, and replace
all the datetimes (both good and flawed) with the calculated datetime.
Here is 1/2 of it:
from datetime import datetime, timedelta
for h in range(8760):
timestamp = datetime(2012,1,1) + timedelta(hours=h)
data_line = "{},{}".format(
timestamp.strftime("%Y-%m-%d,%H:%M"),
"123.456")
print(data_line)
2012-01-01,00:00,123.456
2012-01-01,01:00,123.456
2012-01-01,02:00,123.456
2012-01-01,03:00,123.456
2012-01-01,04:00,123.456
2012-01-01,05:00,123.456
...
2012-12-30,14:00,123.456
2012-12-30,15:00,123.456
2012-12-30,16:00,123.456
2012-12-30,17:00,123.456
2012-12-30,18:00,123.456
2012-12-30,19:00,123.456
2012-12-30,20:00,123.456
2012-12-30,21:00,123.456
2012-12-30,22:00,123.456
2012-12-30,23:00,123.456
If you will post the top of your file, (so I can get csv headers and
data that lines up with my timestamps)
I'll add the rest.
I am guessing you have filenames based on year, like
observation-2012.csv - give me the file name and I'll roll that in.
> Thanks,
>
>
> Rich
>
> _______________________________________________
> PLUG mailing list
> [email protected]
> http://lists.pdxlinux.org/mailman/listinfo/plug
--
Carl K
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug