diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb
old mode 100755
new mode 100644
index c1bb43d..e7fefed
--- a/your-code/challenge-1.ipynb
+++ b/your-code/challenge-1.ipynb
@@ -19,12 +19,13 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "import scipy.stats as st"
]
},
{
@@ -38,11 +39,266 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " # | \n",
+ " Name | \n",
+ " Type 1 | \n",
+ " Type 2 | \n",
+ " Total | \n",
+ " HP | \n",
+ " Attack | \n",
+ " Defense | \n",
+ " Sp. Atk | \n",
+ " Sp. Def | \n",
+ " Speed | \n",
+ " Generation | \n",
+ " Legendary | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Bulbasaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 318 | \n",
+ " 45 | \n",
+ " 49 | \n",
+ " 49 | \n",
+ " 65 | \n",
+ " 65 | \n",
+ " 45 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Ivysaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 405 | \n",
+ " 60 | \n",
+ " 62 | \n",
+ " 63 | \n",
+ " 80 | \n",
+ " 80 | \n",
+ " 60 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 525 | \n",
+ " 80 | \n",
+ " 82 | \n",
+ " 83 | \n",
+ " 100 | \n",
+ " 100 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 3 | \n",
+ " VenusaurMega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 625 | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 309 | \n",
+ " 39 | \n",
+ " 52 | \n",
+ " 43 | \n",
+ " 60 | \n",
+ " 50 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 795 | \n",
+ " 719 | \n",
+ " Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 600 | \n",
+ " 50 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 50 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 796 | \n",
+ " 719 | \n",
+ " DiancieMega Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 700 | \n",
+ " 50 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 110 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 797 | \n",
+ " 720 | \n",
+ " HoopaHoopa Confined | \n",
+ " Psychic | \n",
+ " Ghost | \n",
+ " 600 | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 60 | \n",
+ " 150 | \n",
+ " 130 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 798 | \n",
+ " 720 | \n",
+ " HoopaHoopa Unbound | \n",
+ " Psychic | \n",
+ " Dark | \n",
+ " 680 | \n",
+ " 80 | \n",
+ " 160 | \n",
+ " 60 | \n",
+ " 170 | \n",
+ " 130 | \n",
+ " 80 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 799 | \n",
+ " 721 | \n",
+ " Volcanion | \n",
+ " Fire | \n",
+ " Water | \n",
+ " 600 | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 120 | \n",
+ " 130 | \n",
+ " 90 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
800 rows × 13 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " # Name Type 1 Type 2 Total HP Attack Defense \\\n",
+ "0 1 Bulbasaur Grass Poison 318 45 49 49 \n",
+ "1 2 Ivysaur Grass Poison 405 60 62 63 \n",
+ "2 3 Venusaur Grass Poison 525 80 82 83 \n",
+ "3 3 VenusaurMega Venusaur Grass Poison 625 80 100 123 \n",
+ "4 4 Charmander Fire NaN 309 39 52 43 \n",
+ ".. ... ... ... ... ... .. ... ... \n",
+ "795 719 Diancie Rock Fairy 600 50 100 150 \n",
+ "796 719 DiancieMega Diancie Rock Fairy 700 50 160 110 \n",
+ "797 720 HoopaHoopa Confined Psychic Ghost 600 80 110 60 \n",
+ "798 720 HoopaHoopa Unbound Psychic Dark 680 80 160 60 \n",
+ "799 721 Volcanion Fire Water 600 80 110 120 \n",
+ "\n",
+ " Sp. Atk Sp. Def Speed Generation Legendary \n",
+ "0 65 65 45 1 False \n",
+ "1 80 80 60 1 False \n",
+ "2 100 100 80 1 False \n",
+ "3 122 120 80 1 False \n",
+ "4 60 50 65 1 False \n",
+ ".. ... ... ... ... ... \n",
+ "795 100 150 50 6 True \n",
+ "796 160 110 110 6 True \n",
+ "797 150 130 70 6 True \n",
+ "798 170 130 80 6 True \n",
+ "799 130 90 70 6 True \n",
+ "\n",
+ "[800 rows x 13 columns]"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here:\n"
+ "# Your code here:\n",
+ "data = pd.read_csv('Pokemon.csv')\n",
+ "data"
]
},
{
@@ -58,11 +314,12 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def t_test_features(s1, s2, features=['HP', 'Attack', 'Defense', 'Sp. Atk', 'Sp. Def', 'Speed', 'Total']):\n",
+ " \n",
" \"\"\"Test means of a feature set of two samples\n",
" \n",
" Args:\n",
@@ -76,7 +333,10 @@
" results = {}\n",
"\n",
" # Your code here\n",
- " \n",
+ " for feature in features:\n",
+ " t_stat, p_value = st.ttest_ind(s1[feature], s2[feature], equal_var=False)\n",
+ "\n",
+ " results[feature] = {'t_statistic': t_stat, 'p_value': p_value}\n",
" return results"
]
},
@@ -101,11 +361,44 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([False, True])"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "data[\"Legendary\"].unique()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{'HP': {'t_statistic': 8.981370483625046, 'p_value': 1.0026911708035284e-13}, 'Attack': {'t_statistic': 10.438133539322203, 'p_value': 2.520372449236646e-16}, 'Defense': {'t_statistic': 7.637078164784618, 'p_value': 4.826998494919331e-11}, 'Sp. Atk': {'t_statistic': 13.417449984138461, 'p_value': 1.5514614112239816e-21}, 'Sp. Def': {'t_statistic': 10.015696613114878, 'p_value': 2.2949327864052826e-15}, 'Speed': {'t_statistic': 11.47504444631443, 'p_value': 1.0490163118824507e-18}, 'Total': {'t_statistic': 25.8335743895517, 'p_value': 9.357954335957444e-47}}\n"
+ ]
+ }
+ ],
+ "source": [
+ "# Your code here\n",
+ "legendary = data[data['Legendary'] == True]\n",
+ "non_legendary = data[data['Legendary'] == False]\n",
+ "\n",
+ "t_test_results = t_test_features(legendary, non_legendary, features=[\"HP\", \"Attack\", \"Defense\", \"Sp. Atk\", \"Sp. Def\", \"Speed\", \"Total\"])\n",
+ "print(t_test_results)"
]
},
{
@@ -117,11 +410,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Your comment here\n",
+ "#The p-value is significantly smaller than 0.05. \n",
+ "#Reject the null hypothesis for each feature. \n",
+ "#There is a significant difference in the stats between Legendary and non-Legendary Pokémon."
]
},
{
@@ -133,11 +429,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{'HP': {'t_statistic': -1.4609700002846653, 'p_value': 0.14551697834219626}, 'Attack': {'t_statistic': 1.1603052805533747, 'p_value': 0.24721958967217725}, 'Defense': {'t_statistic': -0.5724173235153119, 'p_value': 0.5677711011725426}, 'Sp. Atk': {'t_statistic': 1.54608675231508, 'p_value': 0.12332165977104388}, 'Sp. Def': {'t_statistic': -1.3203746053318755, 'p_value': 0.18829872292645752}, 'Speed': {'t_statistic': 3.069594374071931, 'p_value': 0.00239265937312135}, 'Total': {'t_statistic': 0.579073329450271, 'p_value': 0.5631377907941676}}\n"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "# Your code here\n",
+ "generation_1 = data[data['Generation'] == 1]\n",
+ "generation_2 = data[data['Generation'] == 2]\n",
+ "\n",
+ "t_test_results = t_test_features(generation_1, generation_2, features=[\"HP\", \"Attack\", \"Defense\", \"Sp. Atk\", \"Sp. Def\", \"Speed\", \"Total\"])\n",
+ "print(t_test_results)"
]
},
{
@@ -149,11 +458,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Your comment here\n",
+ "#The p-value is higher than 0.05. \n",
+ "#Don't reject the null hypothesis for each feature. \n",
+ "#There isn't a significant difference in the stats between Generation1 and Generation 2 Pokemons."
]
},
{
@@ -165,11 +477,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 10,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{'HP': {'t_statistic': -1.586088850338319, 'p_value': 0.11314389855379413}, 'Attack': {'t_statistic': -3.810556219950897, 'p_value': 0.00014932578145948305}, 'Defense': {'t_statistic': -5.60979416640793, 'p_value': 2.7978540411514693e-08}, 'Sp. Atk': {'t_statistic': -3.828976815384819, 'p_value': 0.00013876216585667907}, 'Sp. Def': {'t_statistic': -3.892991138685155, 'p_value': 0.00010730610934512779}, 'Speed': {'t_statistic': -2.258014040079978, 'p_value': 0.02421703281819093}, 'Total': {'t_statistic': -5.355678438759113, 'p_value': 1.1157056505229964e-07}}\n"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "# Your code here\n",
+ "data['Type Count'] = (data['Type 2'].notnull()).astype(int)\n",
+ "\n",
+ "single_type = data[data['Type Count'] == 0] # um tipo, ou seja, não tem o tipo 2\n",
+ "two_types = data[data['Type Count'] == 1] #dois tipos, tem o tipo 1 e o tipo 2\n",
+ "\n",
+ "t_test_results = t_test_features(single_type, two_types, features=[\"HP\", \"Attack\", \"Defense\", \"Sp. Atk\", \"Sp. Def\", \"Speed\", \"Total\"])\n",
+ "print(t_test_results)\n"
]
},
{
@@ -181,11 +508,14 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Your comment here\n",
+ "#The p-value is smaller than 0.05, in almost all features, except HP. \n",
+ "#But we reject the null hypothesis for almost every feature, except HP. \n",
+ "#There is a significant difference in the stats between Single Types and Two Types."
]
},
{
@@ -199,11 +529,49 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 19,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "TtestResult(statistic=4.325566393330478, pvalue=1.7140303479358558e-05, df=799)"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Your code here\n"
+ "# Your code here\n",
+ "from scipy.stats import ttest_rel\n",
+ "#H0: There is no significant difference between the Attack and Defense stats.\n",
+ "#H1: There is a significant difference between the Attack and Defense stats.\n",
+ "\n",
+ "ttest_rel(data[\"Attack\"], data[\"Defense\"])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "TtestResult(statistic=0.853986188453353, pvalue=0.3933685997548122, df=799)"
+ ]
+ },
+ "execution_count": 21,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#H0: There is no significant difference between the Sp. Atk and Sp. Def stats.\n",
+ "#H1: There is a significant difference between the Sp. Atk and Sp. Def stats.\n",
+ "ttest_rel(data[\"Sp. Atk\"], data[\"Sp. Def\"])"
]
},
{
@@ -215,17 +583,26 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Your comment here\n",
+ "#For Attack and Defense, we can see that p-value < 0.05, then we should reject and conclude that there is a significant difference between attack and defense.\n",
+ "##For Sp. Attack and Sp. Def, we can see that p-value > 0.05, then we should not reject and conclude that there is not a significant difference between sp. atk and sp. def."
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -239,7 +616,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.11.5"
}
},
"nbformat": 4,
diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb
old mode 100755
new mode 100644
index 1f0e335..eec4151
--- a/your-code/challenge-2.ipynb
+++ b/your-code/challenge-2.ipynb
@@ -17,21 +17,279 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Import libraries\n",
- "import pandas as pd"
+ "import pandas as pd\n",
+ "from scipy.stats import f_oneway"
]
},
{
"cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
+ "execution_count": 3,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " # | \n",
+ " Name | \n",
+ " Type 1 | \n",
+ " Type 2 | \n",
+ " Total | \n",
+ " HP | \n",
+ " Attack | \n",
+ " Defense | \n",
+ " Sp. Atk | \n",
+ " Sp. Def | \n",
+ " Speed | \n",
+ " Generation | \n",
+ " Legendary | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " 1 | \n",
+ " Bulbasaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 318 | \n",
+ " 45 | \n",
+ " 49 | \n",
+ " 49 | \n",
+ " 65 | \n",
+ " 65 | \n",
+ " 45 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " Ivysaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 405 | \n",
+ " 60 | \n",
+ " 62 | \n",
+ " 63 | \n",
+ " 80 | \n",
+ " 80 | \n",
+ " 60 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 3 | \n",
+ " Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 525 | \n",
+ " 80 | \n",
+ " 82 | \n",
+ " 83 | \n",
+ " 100 | \n",
+ " 100 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 3 | \n",
+ " VenusaurMega Venusaur | \n",
+ " Grass | \n",
+ " Poison | \n",
+ " 625 | \n",
+ " 80 | \n",
+ " 100 | \n",
+ " 123 | \n",
+ " 122 | \n",
+ " 120 | \n",
+ " 80 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 4 | \n",
+ " Charmander | \n",
+ " Fire | \n",
+ " NaN | \n",
+ " 309 | \n",
+ " 39 | \n",
+ " 52 | \n",
+ " 43 | \n",
+ " 60 | \n",
+ " 50 | \n",
+ " 65 | \n",
+ " 1 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 795 | \n",
+ " 719 | \n",
+ " Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 600 | \n",
+ " 50 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 100 | \n",
+ " 150 | \n",
+ " 50 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 796 | \n",
+ " 719 | \n",
+ " DiancieMega Diancie | \n",
+ " Rock | \n",
+ " Fairy | \n",
+ " 700 | \n",
+ " 50 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 160 | \n",
+ " 110 | \n",
+ " 110 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 797 | \n",
+ " 720 | \n",
+ " HoopaHoopa Confined | \n",
+ " Psychic | \n",
+ " Ghost | \n",
+ " 600 | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 60 | \n",
+ " 150 | \n",
+ " 130 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 798 | \n",
+ " 720 | \n",
+ " HoopaHoopa Unbound | \n",
+ " Psychic | \n",
+ " Dark | \n",
+ " 680 | \n",
+ " 80 | \n",
+ " 160 | \n",
+ " 60 | \n",
+ " 170 | \n",
+ " 130 | \n",
+ " 80 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 799 | \n",
+ " 721 | \n",
+ " Volcanion | \n",
+ " Fire | \n",
+ " Water | \n",
+ " 600 | \n",
+ " 80 | \n",
+ " 110 | \n",
+ " 120 | \n",
+ " 130 | \n",
+ " 90 | \n",
+ " 70 | \n",
+ " 6 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
800 rows × 13 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " # Name Type 1 Type 2 Total HP Attack Defense \\\n",
+ "0 1 Bulbasaur Grass Poison 318 45 49 49 \n",
+ "1 2 Ivysaur Grass Poison 405 60 62 63 \n",
+ "2 3 Venusaur Grass Poison 525 80 82 83 \n",
+ "3 3 VenusaurMega Venusaur Grass Poison 625 80 100 123 \n",
+ "4 4 Charmander Fire NaN 309 39 52 43 \n",
+ ".. ... ... ... ... ... .. ... ... \n",
+ "795 719 Diancie Rock Fairy 600 50 100 150 \n",
+ "796 719 DiancieMega Diancie Rock Fairy 700 50 160 110 \n",
+ "797 720 HoopaHoopa Confined Psychic Ghost 600 80 110 60 \n",
+ "798 720 HoopaHoopa Unbound Psychic Dark 680 80 160 60 \n",
+ "799 721 Volcanion Fire Water 600 80 110 120 \n",
+ "\n",
+ " Sp. Atk Sp. Def Speed Generation Legendary \n",
+ "0 65 65 45 1 False \n",
+ "1 80 80 60 1 False \n",
+ "2 100 100 80 1 False \n",
+ "3 122 120 80 1 False \n",
+ "4 60 50 65 1 False \n",
+ ".. ... ... ... ... ... \n",
+ "795 100 150 50 6 True \n",
+ "796 160 110 110 6 True \n",
+ "797 150 130 70 6 True \n",
+ "798 170 130 80 6 True \n",
+ "799 130 90 70 6 True \n",
+ "\n",
+ "[800 rows x 13 columns]"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# Load the data:\n"
+ "# Load the data:\n",
+ "data = pd.read_csv('Pokemon.csv')\n",
+ "data"
]
},
{
@@ -58,12 +316,34 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "['Grass' 'Fire' 'Water' 'Bug' 'Normal' 'Poison' 'Electric' 'Ground'\n",
+ " 'Fairy' 'Fighting' 'Psychic' 'Rock' 'Ghost' 'Ice' 'Dragon' 'Dark' 'Steel'\n",
+ " 'Flying' nan]\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "19"
+ ]
+ },
+ "execution_count": 11,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"# Your code here\n",
+ "unique_types = pd.concat([data['Type 1'], data['Type 2']]).unique()\n",
"\n",
+ "print(unique_types)\n",
"\n",
"len(unique_types) # you should see 19"
]
@@ -85,13 +365,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 39,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "18"
+ ]
+ },
+ "execution_count": 39,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
+ "#Your code here:\n",
+ "\n",
"pokemon_totals = []\n",
"\n",
- "# Your code here\n",
+ "melted_data = pd.melt(data, id_vars='Total', value_vars=['Type 1', 'Type 2'], var_name='Type')\n",
+ "\n",
+ "pokemon_totals = melted_data.dropna().groupby('value')['Total'].sum().tolist()\n",
"\n",
"len(pokemon_totals) # you should see 18"
]
@@ -111,11 +406,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 49,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "ValueError",
+ "evalue": "zero-dimensional arrays cannot be concatenated",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[1;32mIn[49], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# Your code here\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mscipy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mstats\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m f_oneway\n\u001b[1;32m----> 3\u001b[0m anova_result \u001b[38;5;241m=\u001b[39m f_oneway(\u001b[38;5;241m*\u001b[39mpokemon_totals)\n\u001b[0;32m 4\u001b[0m anova_result\n",
+ "File \u001b[1;32m~\\AppData\\Local\\anaconda3\\Lib\\site-packages\\scipy\\stats\\_stats_py.py:4127\u001b[0m, in \u001b[0;36mf_oneway\u001b[1;34m(axis, *samples)\u001b[0m\n\u001b[0;32m 4121\u001b[0m num_groups \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlen\u001b[39m(samples)\n\u001b[0;32m 4123\u001b[0m \u001b[38;5;66;03m# We haven't explicitly validated axis, but if it is bad, this call of\u001b[39;00m\n\u001b[0;32m 4124\u001b[0m \u001b[38;5;66;03m# np.concatenate will raise np.AxisError. The call will raise ValueError\u001b[39;00m\n\u001b[0;32m 4125\u001b[0m \u001b[38;5;66;03m# if the dimensions of all the arrays, except the axis dimension, are not\u001b[39;00m\n\u001b[0;32m 4126\u001b[0m \u001b[38;5;66;03m# the same.\u001b[39;00m\n\u001b[1;32m-> 4127\u001b[0m alldata \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mconcatenate(samples, axis\u001b[38;5;241m=\u001b[39maxis)\n\u001b[0;32m 4128\u001b[0m bign \u001b[38;5;241m=\u001b[39m alldata\u001b[38;5;241m.\u001b[39mshape[axis]\n\u001b[0;32m 4130\u001b[0m \u001b[38;5;66;03m# Check this after forming alldata, so shape errors are detected\u001b[39;00m\n\u001b[0;32m 4131\u001b[0m \u001b[38;5;66;03m# and reported before checking for 0 length inputs.\u001b[39;00m\n",
+ "File \u001b[1;32m<__array_function__ internals>:200\u001b[0m, in \u001b[0;36mconcatenate\u001b[1;34m(*args, **kwargs)\u001b[0m\n",
+ "\u001b[1;31mValueError\u001b[0m: zero-dimensional arrays cannot be concatenated"
+ ]
+ }
+ ],
"source": [
- "# Your code here\n"
+ "# Your code here\n",
+ "from scipy.stats import f_oneway\n",
+ "anova_result = f_oneway(*pokemon_totals)\n",
+ "anova_result"
]
},
{
@@ -127,17 +439,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
- "# Your comment here"
+ "# Your comment here\n"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -151,7 +470,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.11.5"
}
},
"nbformat": 4,