Skip to content
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
202 changes: 193 additions & 9 deletions Desafio_01.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/WittmannF/br-data-science/blob/master/python/challenges/Desafio_1.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/Frascino/br-python-challenges/blob/master/Desafio_01.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand All @@ -57,17 +57,15 @@
"colab": {}
},
"source": [
"# Solução via Data Frame\n",
"palavras = [\n",
" 'red', 'green', 'black', 'pink', 'black', 'white', 'black', 'eyes',\n",
" 'white', 'black', 'orange', 'pink', 'pink', 'red', 'red', 'white', 'orange',\n",
" 'white', \"black\", 'pink', 'green', 'green', 'pink', 'green', 'pink',\n",
" 'white', 'orange', \"orange\", 'red'\n",
"]\n",
"\n",
"\n",
"# Seu código"
"]\n"
],
"execution_count": 0,
"execution_count": 17,
"outputs": []
},
{
Expand All @@ -78,10 +76,196 @@
"colab": {}
},
"source": [
""
"import numpy as np\n",
"import pandas as pd"
],
"execution_count": 0,
"execution_count": 18,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "k1u6Ft_XE3W9",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 266
},
"outputId": "9f1b5ce8-d148-40bc-ed94-9235e2fb873a"
},
"source": [
"df = pd.DataFrame({'cor':palavras})\n",
"df['num'] = 1\n",
"df2 = df.groupby(['cor'],as_index=False).agg({'num':'count'}).sort_values(['num'],ascending=False)\n",
"df2"
],
"execution_count": 19,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cor</th>\n",
" <th>num</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>pink</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>black</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>white</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>green</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>orange</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>red</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>eyes</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" cor num\n",
"4 pink 6\n",
"0 black 5\n",
"6 white 5\n",
"2 green 4\n",
"3 orange 4\n",
"5 red 4\n",
"1 eyes 1"
]
},
"metadata": {
"tags": []
},
"execution_count": 19
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "4FuxyViJ55-g",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 136
},
"outputId": "fffd92b0-c17a-4dad-97b9-b91c1c59ed36"
},
"source": [
"# Solução via set\n",
"palavras_set = set(palavras)\n",
"palavras_set\n",
"for i in palavras_set:\n",
" print(i,palavras.count(i))"
],
"execution_count": 20,
"outputs": [
{
"output_type": "stream",
"text": [
"green 4\n",
"black 5\n",
"orange 4\n",
"red 4\n",
"white 5\n",
"pink 6\n",
"eyes 1\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "sq_6g4FD1guf",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 136
},
"outputId": "856311b3-5935-468c-b9ad-441d335e9092"
},
"source": [
"# Solução via RE\n",
"import re\n",
"\n",
"my_string = 'red green black pink black white black eyes white black orange pink pink red red white orange white black pink green green pink green pink white orange orange red'\n",
"\n",
"words = re.findall(r'\\w+', my_string)\n",
"from collections import Counter\n",
"\n",
"cap_words = [word.upper() for word in words] #capitalizes all the words\n",
"\n",
"word_counts = Counter(cap_words)\n",
"word_counts"
],
"execution_count": 21,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Counter({'BLACK': 5,\n",
" 'EYES': 1,\n",
" 'GREEN': 4,\n",
" 'ORANGE': 4,\n",
" 'PINK': 6,\n",
" 'RED': 4,\n",
" 'WHITE': 5})"
]
},
"metadata": {
"tags": []
},
"execution_count": 21
}
]
}
]
}
}
37 changes: 34 additions & 3 deletions Desafio_02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/WittmannF/br-data-science/blob/master/python/challenges/Desafio_2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/Frascino/br-python-challenges/blob/master/Desafio_02.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand Down Expand Up @@ -68,8 +68,39 @@
"def convert_to_sec(number):\n",
" pass # Seu código"
],
"execution_count": 0,
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "3MzoZgJJIh9V",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 51
},
"outputId": "bf56533f-62cb-4c92-c555-467abd0b3b27"
},
"source": [
"def convert_to_seconds(t):\n",
" seconds = t * 3600\n",
" return seconds\n",
"hours = int(input('How many hours do you want to convert into seconds? '))\n",
"\n",
"print(convert_to_seconds(hours))"
],
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": [
"How many hours do you want to convert into seconds? 10\n",
"36000\n"
],
"name": "stdout"
}
]
}
]
}
}
90 changes: 80 additions & 10 deletions Desafio_03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/WittmannF/br-data-science/blob/master/python/challenges/Desafio_3.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
"<a href=\"https://colab.research.google.com/github/Frascino/br-python-challenges/blob/master/Desafio_03.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
Expand All @@ -57,25 +57,95 @@
"colab": {}
},
"source": [
"lista = [1,2,3,4,3,30,3,4,5,6,9,3,2,1,2,4,5,15,6,6,3,13,4,45,5]\n",
"\n",
"# Seu código"
"# Usando o unique\n",
"lista = [1,2,3,4,3,30,3,4,5,6,9,3,2,1,2,4,5,15,6,6,3,13,4,45,5]\n"
],
"execution_count": 0,
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "wo2rA-NriFtO",
"colab_type": "code",
"colab": {}
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "ec7f1a7f-ae06-41b3-94ae-d61de535a349"
},
"source": [
""
"import numpy as np\n",
"lista = [1,2,3,4,3,30,3,4,5,6,9,3,2,1,2,4,5,15,6,6,3,13,4,45,5]\n",
"print(np.unique(lista))"
],
"execution_count": 0,
"outputs": []
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": [
"[ 1 2 3 4 5 6 9 13 15 30 45]\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "7yqVCMcfJXXi",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "966601f4-080a-4ca2-db27-703b1dbcb11a"
},
"source": [
"print(-np.sort(-np.unique(lista)))"
],
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": [
"[45 30 15 13 9 6 5 4 3 2 1]\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "EuqyYQg_75Ug",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 34
},
"outputId": "df1c3cc1-82f5-4923-f837-f8d4e562bb70"
},
"source": [
"# Usando o set\n",
"lista_set = set(lista)\n",
"lista_set\n"
],
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{1, 2, 3, 4, 5, 6, 9, 13, 15, 30, 45}"
]
},
"metadata": {
"tags": []
},
"execution_count": 7
}
]
}
]
}
}
Loading