Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
df = df[['Global_active_power', 'Global_reactive_power', 'Voltage',
'Global_intensity', 'Sub_metering_2', 'Sub_metering_1','Sub_metering_3']]
def series_to_supervised(data, n_in=1, n_out=1, dropnan=True):
n_vars = 1 if type(data) is list else data.shape[1]
dff = pd.DataFrame(data)
cols, names = list(), list()
for i in range(n_in, 0, -1):
cols.append(dff.shift(-i))
names += [('var%d(t-%d)' % (j+1, i)) for j in range(n_vars)]
for i in range(0, n_out):
cols.append(dff.shift(-i))
if i==0:
names += [('var%d(t)' % (j+1)) for j in range(n_vars)]
else:
names += [('var%d(t+%d)' % (j+1)) for j in range(n_vars)]
agg = pd.concat(cols, axis=1)
agg.columns = names
if dropnan:
agg.dropna(inplace=True)
return agg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment