Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "import pandas as pd\n",
  10. "from sklearn.preprocessing import LabelEncoder"
  11. ]
  12. },
  13. {
  14. "cell_type": "code",
  15. "execution_count": 2,
  16. "metadata": {},
  17. "outputs": [
  18. {
  19. "data": {
  20. "text/html": [
  21. "<div>\n",
  22. "<style scoped>\n",
  23. " .dataframe tbody tr th:only-of-type {\n",
  24. " vertical-align: middle;\n",
  25. " }\n",
  26. "\n",
  27. " .dataframe tbody tr th {\n",
  28. " vertical-align: top;\n",
  29. " }\n",
  30. "\n",
  31. " .dataframe thead th {\n",
  32. " text-align: right;\n",
  33. " }\n",
  34. "</style>\n",
  35. "<table border=\"1\" class=\"dataframe\">\n",
  36. " <thead>\n",
  37. " <tr style=\"text-align: right;\">\n",
  38. " <th></th>\n",
  39. " <th>Car_Manufacturer</th>\n",
  40. " </tr>\n",
  41. " </thead>\n",
  42. " <tbody>\n",
  43. " <tr>\n",
  44. " <th>0</th>\n",
  45. " <td>Toyota</td>\n",
  46. " </tr>\n",
  47. " <tr>\n",
  48. " <th>1</th>\n",
  49. " <td>Ford</td>\n",
  50. " </tr>\n",
  51. " <tr>\n",
  52. " <th>2</th>\n",
  53. " <td>Ford</td>\n",
  54. " </tr>\n",
  55. " <tr>\n",
  56. " <th>3</th>\n",
  57. " <td>Mercedes</td>\n",
  58. " </tr>\n",
  59. " <tr>\n",
  60. " <th>4</th>\n",
  61. " <td>Ford</td>\n",
  62. " </tr>\n",
  63. " </tbody>\n",
  64. "</table>\n",
  65. "</div>"
  66. ],
  67. "text/plain": [
  68. " Car_Manufacturer\n",
  69. "0 Toyota\n",
  70. "1 Ford\n",
  71. "2 Ford\n",
  72. "3 Mercedes\n",
  73. "4 Ford"
  74. ]
  75. },
  76. "execution_count": 2,
  77. "metadata": {},
  78. "output_type": "execute_result"
  79. }
  80. ],
  81. "source": [
  82. "data = pd.DataFrame({'Car_Manufacturer' : ['Toyota', 'Ford', 'Ford', 'Mercedes', 'Ford']})\n",
  83. "data"
  84. ]
  85. },
  86. {
  87. "cell_type": "code",
  88. "execution_count": 3,
  89. "metadata": {},
  90. "outputs": [],
  91. "source": [
  92. "data['Car_Manufacturer'] = pd.factorize(data['Car_Manufacturer'])[0]"
  93. ]
  94. },
  95. {
  96. "cell_type": "code",
  97. "execution_count": 4,
  98. "metadata": {},
  99. "outputs": [
  100. {
  101. "data": {
  102. "text/html": [
  103. "<div>\n",
  104. "<style scoped>\n",
  105. " .dataframe tbody tr th:only-of-type {\n",
  106. " vertical-align: middle;\n",
  107. " }\n",
  108. "\n",
  109. " .dataframe tbody tr th {\n",
  110. " vertical-align: top;\n",
  111. " }\n",
  112. "\n",
  113. " .dataframe thead th {\n",
  114. " text-align: right;\n",
  115. " }\n",
  116. "</style>\n",
  117. "<table border=\"1\" class=\"dataframe\">\n",
  118. " <thead>\n",
  119. " <tr style=\"text-align: right;\">\n",
  120. " <th></th>\n",
  121. " <th>Car_Manufacturer</th>\n",
  122. " </tr>\n",
  123. " </thead>\n",
  124. " <tbody>\n",
  125. " <tr>\n",
  126. " <th>0</th>\n",
  127. " <td>0</td>\n",
  128. " </tr>\n",
  129. " <tr>\n",
  130. " <th>1</th>\n",
  131. " <td>1</td>\n",
  132. " </tr>\n",
  133. " <tr>\n",
  134. " <th>2</th>\n",
  135. " <td>1</td>\n",
  136. " </tr>\n",
  137. " <tr>\n",
  138. " <th>3</th>\n",
  139. " <td>2</td>\n",
  140. " </tr>\n",
  141. " <tr>\n",
  142. " <th>4</th>\n",
  143. " <td>1</td>\n",
  144. " </tr>\n",
  145. " </tbody>\n",
  146. "</table>\n",
  147. "</div>"
  148. ],
  149. "text/plain": [
  150. " Car_Manufacturer\n",
  151. "0 0\n",
  152. "1 1\n",
  153. "2 1\n",
  154. "3 2\n",
  155. "4 1"
  156. ]
  157. },
  158. "execution_count": 4,
  159. "metadata": {},
  160. "output_type": "execute_result"
  161. }
  162. ],
  163. "source": [
  164. "data"
  165. ]
  166. }
  167. ],
  168. "metadata": {
  169. "kernelspec": {
  170. "display_name": "Python 3",
  171. "language": "python",
  172. "name": "python3"
  173. },
  174. "language_info": {
  175. "codemirror_mode": {
  176. "name": "ipython",
  177. "version": 3
  178. },
  179. "file_extension": ".py",
  180. "mimetype": "text/x-python",
  181. "name": "python",
  182. "nbconvert_exporter": "python",
  183. "pygments_lexer": "ipython3",
  184. "version": "3.7.1"
  185. }
  186. },
  187. "nbformat": 4,
  188. "nbformat_minor": 2
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement