Skip to content

Tag: python

Efficiently reading small pieces from multiple h5df files?

I have a hdf5 file every day, which contains compressed data for many assets. Specifically, each h5 file contains 5000 assets, and is organized by key-value structure such as The data of each asset has the same format and size and all together I have around 1000 days of data. Now the task is to do ad-hoc anal…

regex find first occurance beginning from end of the line

I have this string How would I go on about matching from the last occurance of start to the end of the line? I tried to do this with a negative lookahead but I would always get the first occurance: (?!$)\nstart[sS]*?$ Expecting match to be characters: 164-219 Answer You can use See the regex demo. Details: (?…

Python – Reset Increment

I have a list of values in a column (A) and want to increment by 1 in column (B) until the value in A changes, however, having difficulty in my loop to reset the increment when A changes. Here is desired output: Product(A) No.(B) Apple 1 Apple 2 Apple 3 Orange 1 Orange 2 Orange 3 Orange 4 Orange 5

Power Plant – solve the problem in O(nlogn)

I had the following problem on the exam: A certain power plant needs coal to operate, so it has ordered n deliveries, and information about each delivery (number of tons) is stored in a list A. The delivered coal is stored in warehouses with consecutive numbers 0, 1, …. (Their exact number is not given)…