Skip to content

Instantly share code, notes, and snippets.

@jplsightm
Created July 2, 2019 04:07
Show Gist options
  • Save jplsightm/b719f39564764f07dc7b8e1d84db25ac to your computer and use it in GitHub Desktop.
Save jplsightm/b719f39564764f07dc7b8e1d84db25ac to your computer and use it in GitHub Desktop.
For processing tall records. This is a non tested function. Use at your own risk.
import pandas as pd
def sensor_csv(frame, sensor_name, sensor_column, prefix, keep_columns, timestamp):
"""
frame = input frame
sensor_name = sensor name to filter on
sensor_column = column that contains the sensor name
prefix = prefilx to add to column (make themn unique)
keep_columns = what columns should be kept .... I am not doing any checks on data types, make this a list
timestamp = timestamp column
"""
temp = frame[frame[sensor_column] == sensor_name].copy() # initial filter
temp.drop(sensor_column, inplace=True, axis=1) # drop the sensor name column
temp = temp[[timestamp] + keep_columns].copy()
renames = {col: '{}_{}'.format(prefix) for col in temp.columns if col != timestamp}
temp.rename(columns=renames)
return temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment