<jupyter_start><jupyter_text>Finding slopesMuch of the data in energy comes from time series.  We may want to know the slope between points to get the average power between to energy observations.<jupyter_code>import pandas as pd
import io

data_simple = '''date,energy (kWh)
2017-01-01 00:00,0.0
2017-01-01 01:00,1.5
2017-01-01 02:00,3.0
2017-01-01 03:00,4.5
2017-01-01 04:00,6.0
2017-01-01 05:00,7.5
2017-01-01 07:00,10.5
2017-01-01 08:00,12.0
'''

data = pd.read_csv(io.StringIO(data_simple), index_col=0, parse_dates=True)

data['time'] = data.index
%matplotlib inline
data['energy (kWh)'].plot(marker='o', linestyle='')<jupyter_output><empty_output><jupyter_text>We want to find the changes in energy and the changes in time.$$ m = \frac{\Delta E}{\Delta t} $$<jupyter_code>import numpy as np
# note that the slope is for the hour or time period preceding the sample



delta_E = data['energy (kWh)'].diff(1)
delta_E.plot(marker='o', linestyle='')
delta_T_hours = data['time'].diff(1) / np.timedelta64(1, 'h')
delta_T_hours.plot(marker='o', linestyle='')
data['slopes'] = delta_E / delta_T_hours
data['slopes'].plot(marker='o')
# what are the units of this?<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1518456375838926, 'fraction_numerical': 0.10067114093959731, 'mean_word_length': 5.627777777777778, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '536490', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 527, 'n_tokens_neox': 448, 'n_words': 119, 'path': 'data-analysis/finding-slopes.ipynb', 'repo_name': 'dsoto/computing-tutorial', 'size': '1192'}