-1

I am working on a data set that has epoch time. I want to create a new column which splits the time into 10 mins time interval.

Suppose timestamp timeblocks 5:00 1 5:02 1 5:11 2

How can i achieve this using python. I tried resampling but i cannot able further process.

2 Answers2

0

I agree with the comments, you need to provide more. After guessing what you're looking for, you may want histograms where intervals are known as bins. You wrote "10 mins time interval" but your example doesn't show 10 mins.

Python's Numpy and matplotlib have histograms for epochs.

Here's an SO answer on histogram for epoch time.

Saj
  • 781
  • 8
  • 7
0

I'm guessing here, but I believe you are trying to 'bin' your time data into 10 min intervals. Epoch or Unix time is represented as time in seconds (or more commonly nowadays, milliseconds).

First thing you'll need to do is convert each of your epoch time to minutes.

Assuming you have a DataFrame and your epoch are in seconds:

df['min] = df['epoch'] // 60

Once that is done, you can bin your data using pd.cut:

df['bins'] = pd.cut(df['min'], bins=pd.interval_range(start=df['min'].min()-1, end=df['min'].max(), freq=10))

Notice that -1 on start is to shift the first bin to beginning of each 10 min interval.

You'll have your 'bins', you can rename them to your liking and you can groupby them.

The solution may not be perfect, but it will possibly get you on the right track.

Good luck!

Marko Tankosic
  • 164
  • 2
  • 12