Created
July 6, 2018 10:50
-
-
Save abevieiramota/d63ec1b62a0c5295f19e931f68b1776d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from io import StringIO | |
s = """ | |
hora_ini,hora_fim | |
2018-07-01 00:01:00,2018-07-01 00:03:00 | |
2018-07-01 00:00:00,2018-07-01 00:04:00 | |
2018-07-01 00:00:00,2018-07-01 00:01:00 | |
2018-07-01 00:00:01,2018-07-01 00:01:00 | |
""" | |
df = pd.read_csv(StringIO(s), parse_dates=[0, 1]) | |
si = pd.Series(index=df.hora_ini, data=1).resample('T').sum() | |
so = pd.Series(index=df.hora_fim, data=-1).resample('T').sum() | |
rf = pd.concat([si, so], axis=1) | |
rf.cumsum().ffill().sum(axis=1) | |
""" | |
hora_ini | |
2018-07-01 00:00:00 3.0 | |
2018-07-01 00:01:00 2.0 | |
2018-07-01 00:02:00 2.0 | |
2018-07-01 00:03:00 1.0 | |
2018-07-01 00:04:00 0.0 | |
Freq: T, dtype: float64 | |
""" |
rogeriomgatto
commented
Jul 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment