Created
February 16, 2019 16:48
-
-
Save abevieiramota/c1b95bd2d14272e5d4e196ffc57911d8 to your computer and use it in GitHub Desktop.
This file contains 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 | |
ciclo = pd.read_csv('exempo_ciclo.txt', encoding='iso-8859-1', sep='\t') | |
gps = pd.read_csv('exempolo_GPS.txt', encoding='iso-8859-1', sep='\t') | |
ciclo['dataCarregamento'] = pd.to_datetime(ciclo['dataCarregamento'], format='%d/%m/%y %H:%M:%S') | |
ciclo['dataBasculamento'] = pd.to_datetime(ciclo['dataBasculamento'], format='%d/%m/%y %H:%M:%S') | |
gps['Data-Hora'] = pd.to_datetime(gps['Data-Hora'], format='%d/%m/%y %H:%M:%S') | |
gps = gps.sort_values('Data-Hora') | |
ciclo = ciclo.sort_values('dataCarregamento') | |
a = pd.merge_asof(gps, ciclo, left_on='Data-Hora', right_on='dataCarregamento', direction='backward') | |
ciclo = ciclo.sort_values('dataBasculamento') | |
b = pd.merge_asof(gps, ciclo, left_on='Data-Hora', right_on='dataBasculamento', direction='forward') | |
resultado = gps[~(a['Data'].isnull()) & ~(b['Data'].isnull())] | |
resultado.to_csv('resultado.txt', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment