Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eelke #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions 0-03-Crash-Course-Exercises/Crash-Course-Review-Exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,39 @@
#######
# TASK 1: Import pandas and numpy
######

import pandas as pd
import numpy as np


#######
# TASK 2: Set Numpy's random number generator seed to 101
######

np.random.seed(101)


#######
# TASK 3: Create a NumPy Matrix of 100 rows by 5 columns consisting of
# random integers from 1-100. (Keep in mind that the upper
# limit may be exclusive.)
######

arr = np.random.randint(0, 101, (100,5))


#######
# TASK 4: Now use pd.DataFrame() to read in this numpy array as a dataframe.
# Simple pass in the numpy array into that function to get back a
# dataframe. Pandas will auto label the columns to 0-4
######

df = pd.DataFrame(arr)


#######
# TASK 5: Using your previously created DataFrame, use [df.columns = [...]]
# (https://stackoverflow.com/questions/11346283/renaming-columns-in-pandas)
# to rename the pandas columns to be ['f1','f2','f3','f4','label'].
######

df.columns = ['f1', 'f2', 'f3', 'f4', 'label']
print(df)


#######
Expand All @@ -52,3 +54,6 @@
# between 0 and 100. (Hint: Use numpy to create the numbers, then pass
# it in to pd.DataFrame(), check out the data= and index= parameters
# for that call.)
arr = np.random.randint(0,101, (50,4))
df = pd.DataFrame(data=arr, columns=['A','B','C','D'])
print(df)
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import packages\n",
"import numpy as np\n",
"import plotly.offline as pyo\n",
"import plotly.graph_objs as go"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# get consistent random data\n",
"np.random.seed(42)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# create the data\n",
"random_x = np.random.randint(1,101,100)\n",
"random_y = np.random.randint(1,101,100)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'scatterplot_1.html'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create the data variable\n",
"data = [go.Scatter(x=random_x,\n",
" y=random_y,\n",
" mode='markers',\n",
" marker = dict(\n",
" size= 12,\n",
" color= 'rgb(51,204,153)',\n",
" symbol= 'pentagon',\n",
" line = {'width':2}\n",
" ))]\n",
"\n",
"# create the layout variable\n",
"layout = go.Layout(title='Scatterplot 1',\n",
" xaxis={'title':'My x axis'},\n",
" yaxis=dict(title='My y axis'),\n",
" hovermode='closest')\n",
"\n",
"# combine them into a figure\n",
"fig = go.Figure(data=data, layout=layout)\n",
"\n",
"# plot the figure\n",
"pyo.plot(fig, filename='scatterplot_1.html')"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
99 changes: 99 additions & 0 deletions 1-02-ScatterPlots/ScatterPlots_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# import packages\n",
"import numpy as np\n",
"import plotly.offline as pyo\n",
"import plotly.graph_objs as go"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# get consistent random data\n",
"np.random.seed(42)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# create the data\n",
"random_x = np.random.randint(1,101,100)\n",
"random_y = np.random.randint(1,101,100)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'scatterplot_1.html'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create the data variable\n",
"data = [go.Scatter(x=random_x,\n",
" y=random_y,\n",
" mode='markers',\n",
" marker = dict(\n",
" size= 12,\n",
" color= 'rgb(51,204,153)',\n",
" symbol= 'pentagon',\n",
" line = {'width':2}\n",
" ))]\n",
"\n",
"# create the layout variable\n",
"layout = go.Layout(title='Scatterplot 1',\n",
" xaxis={'title':'My x axis'},\n",
" yaxis=dict(title='My y axis'),\n",
" hovermode='closest')\n",
"\n",
"# combine them into a figure\n",
"fig = go.Figure(data=data, layout=layout)\n",
"\n",
"# plot the figure\n",
"pyo.plot(fig, filename='scatterplot_1.html')"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
31 changes: 31 additions & 0 deletions 1-02-ScatterPlots/scatterplot_1.html

Large diffs are not rendered by default.

Loading