I have dataframe like
Date Time nPoints hour
2011-08-01 00:02:21 3 0
2011-08-01 00:04:21 8 0
2011-08-01 00:05:50 2 0
2011-08-01 01:02:21 4 1
2011-08-01 01:03:00 5 1
...
so i want the code that will pick the only the first row of each hour if the datapoints recorded in an hour are more than one. The output would look like
Date Time nPoints hour
2011-08-01 00:02:21 3 0
2011-08-01 01:02:21 4 1
...
I have seen a similar question here: How can i get first value of each hours? ORACLE but it's not a python code
Below is code that i tried, it only returns the list of hours not the whole row as i require
def appendIfNewNumber(unqNumbers, number):
if len(unqNumbers) == 0 or number != unqNumbers[-1]:
unqNumbers.append(number)
unqNumbers = []
for number in df2['hour']:
appendIfNewNumber(unqNumbers, number)
print(unqNumbers)