diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index c574eba..d9923d2 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -33,12 +33,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Durante un tiempo no estuvo segura de si su marido era su marido\n" + ] + } + ], "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", - "# Your code here:\n" + "# Your code here:\n", + "string_1 = \" \".join(str_list)\n", + "print(string_1)" ] }, { @@ -50,12 +60,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Grocery list :Bananas, bread, Brownie Mix, broccoli\n" + ] + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "# Your code here:\n", + "Grocery_string = \",\".join(food_list)\n", + "rule = \"[Bb]\\\\w+\\s?\\w+\"\n", + "print(\"Grocery list :\" + \", \".join(re.findall(rule,Grocery_string)))" ] }, { @@ -69,19 +90,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "insert float:5\n", + "78.53981633974483\n" + ] + } + ], "source": [ "import math\n", "\n", "string1 = \"The area of the circle with radius:\"\n", "string2 = \"is:\"\n", "radius = 4.5\n", + "x= float(input(\"insert float:\"))\n", "\n", "def area(x, pi = math.pi):\n", " # This function takes a radius and returns the area of a circle. We also pass a default value for pi.\n", - " # Input: Float (and default value for pi)\n", + " # Input: Float (and default value for pi)\n", + "\n", " # Output: Float\n", " \n", " # Sample input: 5.0\n", @@ -90,7 +122,9 @@ " # Your code here:\n", " return pi * (x**2)\n", " \n", - "# Your output string here:\n" + "# Your output string here:\n", + "\n", + "print(area(x))" ] }, { @@ -106,9 +140,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Some': 2,\n", + " 'say': 3,\n", + " 'the': 1,\n", + " 'world': 1,\n", + " 'will': 1,\n", + " 'end': 1,\n", + " 'in': 2,\n", + " 'fire': 2,\n", + " 'ice': 2,\n", + " 'From': 1,\n", + " 'what': 1,\n", + " 'I': 4,\n", + " 've': 1,\n", + " 'tasted': 1,\n", + " 'of': 2,\n", + " 'desire': 1,\n", + " 'hold': 1,\n", + " 'with': 1,\n", + " 'those': 1,\n", + " 'who': 1,\n", + " 'favor': 1,\n", + " 'But': 1,\n", + " 'if': 1,\n", + " 'it': 1,\n", + " 'had': 1,\n", + " 'to': 1,\n", + " 'perish': 1,\n", + " 'twice': 1,\n", + " 'think': 1,\n", + " 'know': 1,\n", + " 'enough': 1,\n", + " 'hate': 1,\n", + " 'To': 1,\n", + " 'that': 1,\n", + " 'for': 1,\n", + " 'destruction': 1,\n", + " 'Is': 1,\n", + " 'also': 1,\n", + " 'great': 1,\n", + " 'And': 1,\n", + " 'would': 1,\n", + " 'suffice': 1}" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -120,7 +206,16 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "rule = \"\\\\w+\"\n", + "poem_list= re.findall(rule,poem)\n", + "poem_list\n", + "\n", + "from collections import Counter\n", + "\n", + "word_count = dict(Counter(poem_list))\n", + "\n", + "word_count" ] }, { @@ -132,9 +227,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['I', 'was', 'angry', 'with', 'my', 'friend', 'I', 'told', 'my', 'wrath', 'my', 'wrath', 'did', 'end', 'I', 'was', 'angry', 'with', 'my', 'foe', 'I', 'told', 'it', 'not', 'my', 'wrath', 'did', 'grow', 'And', 'I', 'waterd', 'it', 'in', 'fears', 'Night', 'morning', 'with', 'my', 'tears', 'And', 'I', 'sunned', 'it', 'with', 'smiles', 'And', 'with', 'soft', 'deceitful', 'wiles', 'And', 'it', 'grew', 'both', 'day', 'and', 'night', 'Till', 'it', 'bore', 'an', 'apple', 'bright', 'And', 'my', 'foe', 'beheld', 'it', 'shine', 'And', 'he', 'knew', 'that', 'it', 'was', 'mine', 'And', 'into', 'my', 'garden', 'stole', 'When', 'the', 'night', 'had', 'veild', 'the', 'pole', 'In', 'the', 'morning', 'glad', 'I', 'see', 'My', 'foe', 'outstretched', 'beneath', 'the', 'tree']\n", + "i was angry with my friend i told my wrath my wrath did end i was angry with my foe i told it not my wrath did grow and i waterd it in fears night morning with my tears and i sunned it with smiles and with soft deceitful wiles and it grew both day and night till it bore an apple bright and my foe beheld it shine and he knew that it was mine and into my garden stole when the night had veild the pole in the morning glad i see my foe outstretched beneath the tree\n" + ] + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +262,21 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "rule = \"\\\\w+\"\n", + "poem_list1= re.findall(rule,poem)\n", + "poem_list1\n", + "poem_list2 = []\n", + "for element in (blacklist,poem_list1):\n", + " if element in blacklist:\n", + " poem_list1.remove(element)\n", + "\n", + "print(poem_list1)\n", + "\n", + "poem1 = ' '.join(map(str, poem_list1))\n", + "\n", + "###------\n", + "print(poem1.lower())" ] }, { @@ -172,16 +290,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['The', 'Petals']" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import re\n", "\n", "poem = \"\"\"The apparition of these faces in the crowd;\n", "Petals on a wet, black bough.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "rule = \"[A-Z]\\\\w+\"\n", + "\n", + "re.findall(rule,poem)" ] }, { @@ -193,13 +325,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "data_s = str(data)\n", + "data_s\n", + "match = re.search(\"\\d+?\\w+?\\d+?\",data_s)\n", + "print (match)" ] }, { @@ -215,7 +359,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -226,7 +370,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -240,7 +384,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 6873bd2..1b14bad 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,11 +72,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']" + "import pandas as pd\n", + "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", + "main_dataframe = pd.DataFrame(pd.read_csv(docs[0]))\n", + "\n", + "for i in range(1,len(docs)):\n", + " data = pd.read_csv(docs[i])\n", + " df = pd.DataFrame(data)\n", + " main_dataframe = pd.concat([main_dataframe,df],axis=1)\n", + "list(main_dataframe)" ] }, { @@ -88,11 +107,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Write your code here\n" + "corpus = list(main_dataframe)\n", + "type(corpus)" ] }, { @@ -104,10 +135,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], + "source": [ + "print(corpus)" + ] }, { "cell_type": "markdown", @@ -132,11 +173,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 101, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['ironhack',\n", + " 'is',\n", + " 'cool',\n", + " 'i',\n", + " 'love',\n", + " 'ironhack',\n", + " 'i',\n", + " 'am',\n", + " 'a',\n", + " 'student',\n", + " 'at',\n", + " 'ironhack']" + ] + }, + "execution_count": 101, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Write your code here" + "# Write your code here\n", + "corpus1 = str(corpus)\n", + "corpus_lower= str((corpus1.lower()))\n", + "import re\n", + "rule = \"\\w+\"\n", + "corpus_l = re.findall(rule, corpus_lower)\n", + "corpus_l" ] }, { @@ -148,10 +217,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 102, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "bag_of_words = []" + ] }, { "cell_type": "markdown", @@ -166,11 +237,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 117, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['am', 'a', 'at', 'is', 'cool', 'love', 'i', 'student', 'ironhack']\n" + ] + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "bag_of_words1 = set(corpus_l)\n", + "bag_of_words = list(bag_of_words1)\n", + "print(bag_of_words)" ] }, { @@ -200,11 +282,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 120, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['am', 'a', 'at', 'is', 'cool', 'love', 'i', 'student', 'ironhack']" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "corpus\n", + "bag_of_words" ] }, { @@ -218,10 +313,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 121, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 1, 1, 1, 0, 0],\n", + " [0, 0, 0, 1, 0, 1, 0],\n", + " [1, 1, 0, 1, 0, 0, 1]], dtype=int64)" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from sklearn.feature_extraction.text import CountVectorizer\n", + "vectorizer = CountVectorizer()\n", + "corpus \n", + "term_freq = vectorizer.fit_transform(corpus)\n", + "term_freq.toarray() " + ] }, { "cell_type": "markdown", @@ -304,7 +418,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -318,7 +432,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.9.7" } }, "nbformat": 4,