Skip to content

Commit

Permalink
add notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Apr 4, 2023
1 parent 5e04609 commit 0d769cd
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions vscode/notebooks/data.ipynb
@@ -0,0 +1,132 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## DeviceScript Data\n",
"\n",
"### Setup\n",
"\n",
"Run `pip install pandas matplotlib` to load the necessary python libs.\n",
"\n",
"### Loading data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"parameters"
]
},
"outputs": [],
"source": [
"# what file are you analyzing today?\n",
"file = '2023-04-03-15-16.csv'"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"This snippet loads the CSV in a panda dataframe, fills the empty cells and displays basic statistical values about the data."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"df = pd.read_csv(file, index_col='time')\n",
"df.head()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cleanup\n",
"\n",
"Because of the unstructured way `console.data` collects data points, there may be empty cells. One strategy is to fill empty cells with the previous known values."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.fillna(method='ffill', inplace=True) # fill missing values with previous known values\n",
"df.fillna(method='backfill', inplace=True) # fill missing values with next known values\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.describe()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting data\n",
"\n",
"We're now ready to plot this data using matplotlib."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"fig, ax = plt.subplots(figsize=(12, 6)) # set figsize to (width, height)\n",
"# plot all columns, expect index\n",
"for i, col in enumerate(df.columns):\n",
" ax.plot(df.index, df[col], label=col)\n",
"ax.set_xlabel('time')\n",
"ax.legend()\n",
"plt.show()\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.2"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 0d769cd

Please sign in to comment.