Skip to content

Instantly share code, notes, and snippets.

Created Oct 5, 2020
What would you like to do?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import pandas as pd
# Como viene una columna de vecha y 4 de hora, hay que parsearlas convinadas
rdf = pd.read_excel('data.xlsx', header = None, parse_dates = [[0,1], [0,3], [0,5], [0,7]])
# Renombramos las columnas y concatenamos en una sola tabla de timestamp y altura
col_map = {
'0_1': 'datetime',
'0_3': 'datetime',
'0_5': 'datetime',
'0_7': 'datetime',
2: 'rheight',
4: 'rheight',
6: 'rheight',
8: 'rheight',
frames = [rdf[['0_1', 2]].rename(columns=col_map),
rdf[['0_3', 4]].rename(columns=col_map),
rdf[['0_5', 6]].rename(columns=col_map),
rdf[['0_7', 8]].rename(columns=col_map)]
edf = pd.concat(frames).dropna()
# Eliminamos los 2 ultimos caracteres del valor de altura y lo convertimos de str a float
edf['height'] = edf.rheight.str[:-2].apply(float)
# ordenamos y eliminamos la altura cruda (string)
df = edf.drop(columns=['rheight']).sort_values(by='datetime').set_index('datetime')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment