{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f1acd866",
   "metadata": {},
   "outputs": [],
   "source": [
    "pos= open('positive.txt','r').read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "08fa198d",
   "metadata": {},
   "outputs": [],
   "source": [
    "neg= open('negative.txt','r').read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0b9e046f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import nltk\n",
    "import re\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6827e073",
   "metadata": {},
   "outputs": [],
   "source": [
    "test= open('test.srt','r').read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f0cabfe3",
   "metadata": {},
   "outputs": [],
   "source": [
    "characters_to_remove = \"]!()-@0123456789:->,'[\"\n",
    "pattern = \"[\" + characters_to_remove + \"]\"\n",
    "test= re.sub(pattern, \"\", test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1924d6b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "sent = nltk.tokenize.PunktSentenceTokenizer().tokenize(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1b4c6b1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "words= nltk.tokenize.wordpunct_tokenize(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "74115f66",
   "metadata": {},
   "outputs": [],
   "source": [
    "words2=nltk.tokenize.word_tokenize(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b3cd7edd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9864"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2023d52e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9770"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(words2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1817a2f7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "4e88b559",
   "metadata": {},
   "outputs": [],
   "source": [
    "sent= nltk.tokenize.LineTokenizer().tokenize(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbfac454",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40e42062",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "207ba393",
   "metadata": {},
   "outputs": [],
   "source": [
    "word_frq= nltk.FreqDist(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "93742ea7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2005"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(word_frq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e458c57",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a98c9a0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "words_frq= nltk.FreqDist(words2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1fe9ad2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "5f5b4662",
   "metadata": {},
   "outputs": [],
   "source": [
    "import spacy\n",
    "nlp= spacy.load('en_core_web_sm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "3125cf03",
   "metadata": {},
   "outputs": [],
   "source": [
    "w= nlp(test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca3fe86d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "180a4353",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(8)\n",
    "b = a[4:6]\n",
    "b[:] = 40\n",
    "c = a[4] + a[6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d6311fed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "46"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2952e1f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "s = 'ABCAC'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6fa528ba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(re.match('A', s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8f95d2c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(re.split('A', s)) == 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "b64d80ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8b37201a",
   "metadata": {},
   "outputs": [],
   "source": [
    "s1= pd.Series({'m':20,'s':15,'b':18,'v':31})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f0a1b10b",
   "metadata": {},
   "outputs": [],
   "source": [
    "s2= pd.Series({'s':20,'v':30,'b':15,'m':20,'p':20})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6e6c5d41",
   "metadata": {},
   "outputs": [],
   "source": [
    "s3 = s1.add(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1727e5ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b    33.0\n",
       "m    40.0\n",
       "p     NaN\n",
       "s    35.0\n",
       "v    61.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "fdcf955e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3['m'] >=  s1.add(s2, fill_value = 0)['m']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1a5ea20c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "33.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3['b'] == s1.add(s2, fill_value = 0)['b']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "de43ba99",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3['p'] >= s3['m']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "aa999e4c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s3['b'] == s1['b']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "1ac83af3",
   "metadata": {},
   "outputs": [],
   "source": [
    "S = pd.Series(np.arange(5), index=['a', 'b', 'c', 'd', 'e'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e21b9fb6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b    1\n",
       "c    2\n",
       "d    3\n",
       "e    4\n",
       "dtype: int32"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S['b':'e']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "dc719c8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b    1\n",
       "c    2\n",
       "d    3\n",
       "dtype: int32"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S[['b', 'c', 'd']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "67d408c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b    1\n",
       "c    2\n",
       "d    3\n",
       "dtype: int32"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S[S <= 3][S > 0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "353bc310",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "a = np.arange(8)\n",
    "b = a[4:6]\n",
    "b[:] = 40\n",
    "c = a[4] + a[6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "6b3fac3d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "46"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "3dbff302",
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "s = 'ABCAC'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "f8e56493",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bool(re.match('A', s)) == True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "b8138ac9",
   "metadata": {},
   "outputs": [],
   "source": [
    "df= pd.DataFrame({'item':[1,1,1,2,2,2], 'store':['a','b','c','a','b','c'],'q':[10,20,np.nan,5,10,15]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "5ea558a8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('item').sum().iloc[0]['q']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "f0fea7ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "df= pd.DataFrame({'a':[5,4,71,67],'b':[6,82,31,37],'c':[20,28,92,49]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "ef879d75",
   "metadata": {},
   "outputs": [],
   "source": [
    "f = lambda x: x.max() + x.min()\n",
    "df_new = df.apply(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "d750b344",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a     75\n",
       "b     88\n",
       "c    112\n",
       "dtype: int64"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "4d0eb3fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "s='I completed my BE in Mechanical engineering in 2016, and I was working in a small COMPANY. Last year due to Covid I lost my job and now there are very few hirings in the field of mechanical engineering. I have a family of four and I was the only earning member. I have been working freelance in the stock market for the last two years and it hasnt been enough. My family has been surviving on my savings. The mechanical industry isnt growing at the pace it used to, and I have always been fascinated with programming languages and I have a good grasp of basic python. So I have decided to switch careers and thinking of entering the field of data science.'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "327b69b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import nltk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3863f004",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['I', 'completed', 'my', 'BE', 'in', 'Mechanical', 'engineering', 'in', '2016', ',', 'and', 'I', 'was', 'working', 'in', 'a', 'small', 'COMPANY', '.', 'Last', 'year', 'due', 'to', 'Covid', 'I', 'lost', 'my', 'job', 'and', 'now', 'there', 'are', 'very', 'few', 'hirings', 'in', 'the', 'field', 'of', 'mechanical', 'engineering', '.', 'I', 'have', 'a', 'family', 'of', 'four', 'and', 'I', 'was', 'the', 'only', 'earning', 'member', '.', 'I', 'have', 'been', 'working', 'freelance', 'in', 'the', 'stock', 'market', 'for', 'the', 'last', 'two', 'years', 'and', 'it', 'hasnt', 'been', 'enough', '.', 'My', 'family', 'has', 'been', 'surviving', 'on', 'my', 'savings', '.', 'The', 'mechanical', 'industry', 'isnt', 'growing', 'at', 'the', 'pace', 'it', 'used', 'to', ',', 'and', 'I', 'have', 'always', 'been', 'fascinated', 'with', 'programming', 'languages', 'and', 'I', 'have', 'a', 'good', 'grasp', 'of', 'basic', 'python', '.', 'So', 'I', 'have', 'decided', 'to', 'switch', 'careers', 'and', 'thinking', 'of', 'entering', 'the', 'field', 'of', 'data', 'science', '.']\n"
     ]
    }
   ],
   "source": [
    "print(nltk.tokenize.word_tokenize(s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b873271a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
