Skip to content

Instantly share code, notes, and snippets.

@ccisne
Created December 6, 2020 17:15
Show Gist options
  • Save ccisne/3b9af0ed8c02e4e162dea9df706e6d89 to your computer and use it in GitHub Desktop.
Save ccisne/3b9af0ed8c02e4e162dea9df706e6d89 to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Statistics Introduction Applied to Data Science\n",
"## Lab : Two\n",
"### Data types in Python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Others data types"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Lists\n",
"Python lists are mutable sequences. They are very similar to tuples, but they don't have the restrictions of inmutability."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = [1,2,3,4]\n",
"type(y)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Lists can have both number and text.\n",
"y = [1,2,3,'a','b','c']\n",
"type(y)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 'a', 10, 'c']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y[4] = 10\n",
"y"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"#### Tuples"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 2, 3, 'a', 'b', 'c')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Tuples are not mutables.\n",
"z = (1,2,3, 'a', 'b', 'c')\n",
"z"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(z)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Dictionaries\n",
"Dictionaries are mutable objects. A dictionary maps keys to values."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{0: 'Men', 1: 'Woman'}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Gender dictionary.\n",
"gender = {0:\"Men\", 1:\"Woman\"}\n",
"gender"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Woman'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gender[1]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(gender)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Sets\n",
"A feature of sets is the duplication isn't allowed."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{1, 2, 3}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = {1,1,1,1,1,1,1,2,2,3,3,3,3,3,3,3,3,3}\n",
"x"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"set"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Practice One: Print a list of your three favorite foods."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Sea Food', 'fries', 'Cesar Salad']\n"
]
}
],
"source": [
"# Type your code here\n",
"my_food = ['Sea Food','fries','Cesar Salad']\n",
"print(my_food)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Practice Two: Create a dictionary with keys 1, 2, 3, and values \"Low\", \"Medium\", \"High\". Assign it to \"income\" variable."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Type your code here\n",
"income = {\n",
" 1: \"Low\",\n",
" 2: \"Medium\",\n",
" 3: \"High\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{1: 'Low', 2: 'Medium', 3: 'High'}\n"
]
}
],
"source": [
"print(income)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Practice Three: Print \"High\" value from dictionary. Remember, use the key."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"High\n"
]
}
],
"source": [
"# Type your code here\n",
"print(income[3])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"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.6.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment