Filtering by minute with pandas

Question:

Ok so I have a dataset/frame with pandas and I want to select one row per minute to get a more accurate view of the simulation. As the times in the dataframe are too close together.

as seen in the picture under local time I have very many timestamps per minute

req_columns = [4,5,6, 9]
df = pd.read_excel('Flt0052UV.xlsx', skiprows = range(1,33656), usecols= req_columns)
df = df[~df.Longitude.isnull()]

here is how I currently select the data any help would be greatly appreciated.

Asked By: JaredCusick

||

Answers:

Use resample() on your datetime with first().

import pandas as pd

df = pd.DataFrame(data=[i for i in range(3600)], index=pd.date_range(start='01/01/2022', periods=3600, freq='s'), columns=['data'])

df = df.resample('1min').first()

Output:

                     data
2022-01-01 00:00:00     0
2022-01-01 00:01:00    60
2022-01-01 00:02:00   120
2022-01-01 00:03:00   180
         ...          ...
Answered By: Stu Sztukowski
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.