Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14097

How to split a DataFrame into separate groups based on a Value(Difference Value of Time)

$
0
0

I'm now using Pandas in Python to handle some data.

Simplified DataFrame is

[ID, TimeDiff] and some other not-important columns.

For example:

73    1.16666774    1.16666775    2.18333376    3.46666777    2.66666778    Na

TimeDiff means the difference value of time in data ID. 3.466667 means the time between ID 76 and ID 77 is 3.466667 hours.I want to split vessel data to make sure the difference value of time is within 2 hoursso I need to split DataFrame into N different groups (in this example, N = 4).

I need to get results like this: whenever TimeDiff >= 2 create another group

--------------73    1.16666774    1.166667-------------75    2.183333--------------76    3.466667--------------77         NaN

I have tried to use Groupby in pandas.

df.groupby('TimeDiff')   

But obviously, this is not what I want.I'm now trying to split DataFrame step by step like this:From

73    1.16666774    1.166667--------------75    2.18333376    3.46666777    2.66666778    Na

To

73    1.16666774    1.166667--------------75    2.183333--------------76    3.46666777    2.66666778    Na

Then To

73    1.16666774    1.166667--------------75    2.183333--------------76    3.46666777    2.66666778    Na

......

Finally to what I want:

--------------73    1.16666774    1.166667-------------75    2.183333--------------76    3.466667--------------77         NaN

4 groups Data. But after searching Google and StackOverflow I didn't find a proper way to handle it. Can somebody help me?


Viewing all articles
Browse latest Browse all 14097

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>