From 0eb7405b5f09900a4aa85c819e6f34eb6eaab9c0 Mon Sep 17 00:00:00 2001 From: Mojtaba Peyrovi Date: Wed, 4 Oct 2023 20:08:12 +0200 Subject: [PATCH 1/3] coded along until mid unit1, lesson 8 --- moji-codealong/lesson1/read_csv.ipynb | 483 ++++++++++++++++++++++++++ moji-codealong/lesson8/notebook.ipynb | 443 +++++++++++++++++++++++ 2 files changed, 926 insertions(+) create mode 100644 moji-codealong/lesson1/read_csv.ipynb create mode 100644 moji-codealong/lesson8/notebook.ipynb diff --git a/moji-codealong/lesson1/read_csv.ipynb b/moji-codealong/lesson1/read_csv.ipynb new file mode 100644 index 0000000..8bb0fff --- /dev/null +++ b/moji-codealong/lesson1/read_csv.ipynb @@ -0,0 +1,483 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "<_io.TextIOWrapper name='C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-1-reading-csv-and-txt-files\\\\files\\\\btc-market-price.csv' mode='r' encoding='cp1252'>\n" + ] + } + ], + "source": [ + "filepath = 'C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-1-reading-csv-and-txt-files\\\\files\\\\btc-market-price.csv'\n", + "with open(filepath, 'r') as reader:\n", + " print(reader)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 2/4/17 0:00,1099.169125\n", + "\n", + "1 3/4/17 0:00,1141.813\n", + "\n", + "2 4/4/17 0:00,?\n", + "\n", + "3 5/4/17 0:00,1133.079314\n", + "\n", + "4 6/4/17 0:00,-\n", + "\n", + "5 7/4/17 0:00,-\n", + "\n", + "6 8/4/17 0:00,1181.149838\n", + "\n", + "7 9/4/17 0:00,1208.8005\n", + "\n", + "8 10/4/17 0:00,1207.744875\n", + "\n", + "9 11/4/17 0:00,1226.617038\n", + "\n" + ] + } + ], + "source": [ + "with open(filepath, 'r') as reader:\n", + " for index, line in enumerate(reader.readlines()):\n", + " if (index < 10):\n", + " print(index, line)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\mojta\\AppData\\Local\\Temp\\ipykernel_20664\\717812342.py:1: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.\n", + " df = pd.read_csv(filepath, header=None, na_values=['','?','-'], names=['Timestamp','Price'],\\\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Price
Timestamp
2017-02-041099.169125
2017-03-041141.813000
2017-04-04NaN
2017-05-041133.079314
2017-06-04NaN
\n", + "
" + ], + "text/plain": [ + " Price\n", + "Timestamp \n", + "2017-02-04 1099.169125\n", + "2017-03-04 1141.813000\n", + "2017-04-04 NaN\n", + "2017-05-04 1133.079314\n", + "2017-06-04 NaN" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = pd.read_csv(filepath, header=None, na_values=['','?','-'], names=['Timestamp','Price'],\\\n", + " dtype={'Price': 'float'}, index_col='Timestamp', parse_dates=[0])\n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "# df['Timestamp'] = pd.to_datetime(df['Timestamp'], format='%Y-%m-%d %H-%M-%S')" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
first_name>last_name>age>math_score>french_score
Ray>Morley>18>\"68000\">\"75000\"
Melvin>Scott>24>77>83NaNNaN
Amirah>Haley>22>92>67NaNNaN
Gerard>Mills>19>\"78000\">72NaN
Amy>Grimes>23>91>81NaNNaN
\n", + "
" + ], + "text/plain": [ + " first_name>last_name>age>math_score>french_score\n", + "Ray>Morley>18>\"68 000\">\"75 000\"\n", + "Melvin>Scott>24>77>83 NaN NaN\n", + "Amirah>Haley>22>92>67 NaN NaN\n", + "Gerard>Mills>19>\"78 000\">72 NaN\n", + "Amy>Grimes>23>91>81 NaN NaN" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "exam_df = pd.read_csv('C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-1-reading-csv-and-txt-files\\\\files\\\\exam_review.csv')\n", + "exam_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
first_namelast_nameagemath_scorefrench_score
0RayMorley1868.075.0
1MelvinScott2477.083.0
2AmirahHaley2292.067.0
3GerardMills1978.072.0
4AmyGrimes2391.081.0
\n", + "
" + ], + "text/plain": [ + " first_name last_name age math_score french_score\n", + "0 Ray Morley 18 68.0 75.0\n", + "1 Melvin Scott 24 77.0 83.0\n", + "2 Amirah Haley 22 92.0 67.0\n", + "3 Gerard Mills 19 78.0 72.0\n", + "4 Amy Grimes 23 91.0 81.0" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "exam_df = pd.read_csv('C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-1-reading-csv-and-txt-files\\\\files\\\\exam_review.csv',\n", + " sep='>', decimal=',', skip_blank_lines=True)\n", + "\n", + "exam_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
first_namelast_name
0RayMorley
1MelvinScott
2AmirahHaley
3GerardMills
4AmyGrimes
\n", + "
" + ], + "text/plain": [ + " first_name last_name\n", + "0 Ray Morley\n", + "1 Melvin Scott\n", + "2 Amirah Haley\n", + "3 Gerard Mills\n", + "4 Amy Grimes" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "exam_df = pd.read_csv('C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-1-reading-csv-and-txt-files\\\\files\\\\exam_review.csv',\n", + " sep='>', decimal=',', skip_blank_lines=True, usecols=['first_name', 'last_name'])\n", + "\n", + "exam_df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "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.11.4" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/moji-codealong/lesson8/notebook.ipynb b/moji-codealong/lesson8/notebook.ipynb new file mode 100644 index 0000000..384abca --- /dev/null +++ b/moji-codealong/lesson8/notebook.ipynb @@ -0,0 +1,443 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
titlepricecontent_rating_imgrelease_dateprovidergenreimage
0Call of Duty®: WWII + Destiny 2 - Lote129,99 €https://cdn-a.sonyentertainmentnetwork.com/grc...Dic 21 2018Activision Blizzard Int'l BVShooterhttps://store.playstation.com/store/api/chihir...
1God of War® Digital Deluxe Edition69,99 €https://cdn-a.sonyentertainmentnetwork.com/grc...Abr 20 2018Sony Interactive Entertainment EuropeAcciónhttps://store.playstation.com/store/api/chihir...
2Far Cry 569,99 €https://cdn-a.sonyentertainmentnetwork.com/grc...Mar 27 2018UBISOFT ENTERTAINMENT SAAventurahttps://store.playstation.com/store/api/chihir...
3Far Cry 5 Edición Deluxe79,99 €https://cdn-a.sonyentertainmentnetwork.com/grc...Mar 27 2018UBISOFT ENTERTAINMENT SAAventurahttps://store.playstation.com/store/api/chihir...
4Far Cry 5 Edición Oro89,99 €https://cdn-a.sonyentertainmentnetwork.com/grc...Mar 27 2018UBISOFT ENTERTAINMENT SAAventurahttps://store.playstation.com/store/api/chihir...
\n", + "
" + ], + "text/plain": [ + " title price \\\n", + "0 Call of Duty®: WWII + Destiny 2 - Lote 129,99 € \n", + "1 God of War® Digital Deluxe Edition 69,99 € \n", + "2 Far Cry 5 69,99 € \n", + "3 Far Cry 5 Edición Deluxe 79,99 € \n", + "4 Far Cry 5 Edición Oro 89,99 € \n", + "\n", + " content_rating_img release_date \\\n", + "0 https://cdn-a.sonyentertainmentnetwork.com/grc... Dic 21 2018 \n", + "1 https://cdn-a.sonyentertainmentnetwork.com/grc... Abr 20 2018 \n", + "2 https://cdn-a.sonyentertainmentnetwork.com/grc... Mar 27 2018 \n", + "3 https://cdn-a.sonyentertainmentnetwork.com/grc... Mar 27 2018 \n", + "4 https://cdn-a.sonyentertainmentnetwork.com/grc... Mar 27 2018 \n", + "\n", + " provider genre \\\n", + "0 Activision Blizzard Int'l BV Shooter \n", + "1 Sony Interactive Entertainment Europe Acción \n", + "2 UBISOFT ENTERTAINMENT SA Aventura \n", + "3 UBISOFT ENTERTAINMENT SA Aventura \n", + "4 UBISOFT ENTERTAINMENT SA Aventura \n", + "\n", + " image \n", + "0 https://store.playstation.com/store/api/chihir... \n", + "1 https://store.playstation.com/store/api/chihir... \n", + "2 https://store.playstation.com/store/api/chihir... \n", + "3 https://store.playstation.com/store/api/chihir... \n", + "4 https://store.playstation.com/store/api/chihir... " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "games = pd.read_json('C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-8-reading-json-files\\\\files\\\\games.json')\n", + "games.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
info
0{'id': 1, 'name': 'Leanne Graham', 'username':...
1{'id': 2, 'name': 'Ervin Howell', 'username': ...
2{'id': 3, 'name': 'Clementine Bauch', 'usernam...
3{'id': 4, 'name': 'Patricia Lebsack', 'usernam...
4{'id': 5, 'name': 'Chelsey Dietrich', 'usernam...
\n", + "
" + ], + "text/plain": [ + " info\n", + "0 {'id': 1, 'name': 'Leanne Graham', 'username':...\n", + "1 {'id': 2, 'name': 'Ervin Howell', 'username': ...\n", + "2 {'id': 3, 'name': 'Clementine Bauch', 'usernam...\n", + "3 {'id': 4, 'name': 'Patricia Lebsack', 'usernam...\n", + "4 {'id': 5, 'name': 'Chelsey Dietrich', 'usernam..." + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "df = pd.read_json('C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-8-reading-json-files\\\\files\\\\users.json')\n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "with open('C:\\\\Users\\\\mojta\\\\personal_projects\\\\RDP-Reading-Data-with-Python-and-Pandas\\\\unit-1-reading-data-with-python-and-pandas\\\\lesson-8-reading-json-files\\\\files\\\\users.json') as f:\n", + " json_dict = json.load(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['info'])" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "json_dict.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_values([[{'id': 1, 'name': 'Leanne Graham', 'username': 'Bret', 'email': 'Sincere@april.biz', 'address': [{'street': 'Kulas Light', 'suite': 'Apt. 556', 'city': 'Gwenborough', 'zipcode': '92998-3874', 'geo': {'lat': '-37.3159', 'lng': '81.1496'}}], 'phone': '1-770-736-8031 x56442', 'website': 'hildegard.org', 'company': {'name': 'Romaguera-Crona', 'catchPhrase': 'Multi-layered client-server neural-net', 'bs': 'harness real-time e-markets'}}, {'id': 2, 'name': 'Ervin Howell', 'username': 'Antonette', 'email': 'Shanna@melissa.tv', 'address': [{'street': 'Victor Plains', 'suite': 'Suite 879', 'city': 'Wisokyburgh', 'zipcode': '90566-7771', 'geo': {'lat': '-43.9509', 'lng': '-34.4618'}}], 'phone': '010-692-6593 x09125', 'website': 'anastasia.net', 'company': {'name': 'Deckow-Crist', 'catchPhrase': 'Proactive didactic contingency', 'bs': 'synergize scalable supply-chains'}}, {'id': 3, 'name': 'Clementine Bauch', 'username': 'Samantha', 'email': 'Nathan@yesenia.net', 'address': [{'street': 'Douglas Extension', 'suite': 'Suite 847', 'city': 'McKenziehaven', 'zipcode': '59590-4157', 'geo': {'lat': '-68.6102', 'lng': '-47.0653'}}], 'phone': '1-463-123-4447', 'website': 'ramiro.info', 'company': {'name': 'Romaguera-Jacobson', 'catchPhrase': 'Face to face bifurcated interface', 'bs': 'e-enable strategic applications'}}, {'id': 4, 'name': 'Patricia Lebsack', 'username': 'Karianne', 'email': 'Julianne.OConner@kory.org', 'address': [{'street': 'Hoeger Mall', 'suite': 'Apt. 692', 'city': 'South Elvis', 'zipcode': '53919-4257', 'geo': {'lat': '29.4572', 'lng': '-164.2990'}}], 'phone': '493-170-9623 x156', 'website': 'kale.biz', 'company': {'name': 'Robel-Corkery', 'catchPhrase': 'Multi-tiered zero tolerance productivity', 'bs': 'transition cutting-edge web services'}}, {'id': 5, 'name': 'Chelsey Dietrich', 'username': 'Kamren', 'email': 'Lucio_Hettinger@annie.ca', 'address': [{'street': 'Skiles Walks', 'suite': 'Suite 351', 'city': 'Roscoeview', 'zipcode': '33263', 'geo': {'lat': '-31.8129', 'lng': '62.5342'}}], 'phone': '(254)954-1289', 'website': 'demarco.info', 'company': {'name': 'Keebler LLC', 'catchPhrase': 'User-centric fault-tolerant solution', 'bs': 'revolutionize end-to-end systems'}}, {'id': 6, 'name': 'Mrs. Dennis Schulist', 'username': 'Leopoldo_Corkery', 'email': 'Karley_Dach@jasper.info', 'address': [{'street': 'Norberto Crossing', 'suite': 'Apt. 950', 'city': 'South Christy', 'zipcode': '23505-1337', 'geo': {'lat': '-71.4197', 'lng': '71.7478'}}], 'phone': '1-477-935-8478 x6430', 'website': 'ola.org', 'company': {'name': 'Considine-Lockman', 'catchPhrase': 'Synchronised bottom-line interface', 'bs': 'e-enable innovative applications'}}, {'id': 7, 'name': 'Kurtis Weissnat', 'username': 'Elwyn.Skiles', 'email': 'Telly.Hoeger@billy.biz', 'address': [{'street': 'Rex Trail', 'suite': 'Suite 280', 'city': 'Howemouth', 'zipcode': '58804-1099', 'geo': {'lat': '24.8918', 'lng': '21.8984'}}], 'phone': '210.067.6132', 'website': 'elvis.io', 'company': {'name': 'Johns Group', 'catchPhrase': 'Configurable multimedia task-force', 'bs': 'generate enterprise e-tailers'}}, {'id': 8, 'name': 'Nicholas Runolfsdottir V', 'username': 'Maxime_Nienow', 'email': 'Sherwood@rosamond.me', 'address': [{'street': 'Ellsworth Summit', 'suite': 'Suite 729', 'city': 'Aliyaview', 'zipcode': '45169', 'geo': {'lat': '-14.3990', 'lng': '-120.7677'}}], 'phone': '586.493.6943 x140', 'website': 'jacynthe.com', 'company': {'name': 'Abernathy Group', 'catchPhrase': 'Implemented secondary concept', 'bs': 'e-enable extensible e-tailers'}}, {'id': 9, 'name': 'Glenna Reichert', 'username': 'Delphine', 'email': 'Chaim_McDermott@dana.io', 'address': [{'street': 'Dayna Park', 'suite': 'Suite 449', 'city': 'Bartholomebury', 'zipcode': '76495-3109', 'geo': {'lat': '24.6463', 'lng': '-168.8889'}}], 'phone': '(775)976-6794 x41206', 'website': 'conrad.com', 'company': {'name': 'Yost and Sons', 'catchPhrase': 'Switchable contextually-based project', 'bs': 'aggregate real-time technologies'}}, {'id': 10, 'name': 'Clementina DuBuque', 'username': 'Moriah.Stanton', 'email': 'Rey.Padberg@karina.biz', 'address': [{'street': 'Kattie Turnpike', 'suite': 'Suite 198', 'city': 'Lebsackbury', 'zipcode': '31428-2261', 'geo': {'lat': '-38.2386', 'lng': '57.2232'}}], 'phone': '024-648-3804', 'website': 'ambrose.net', 'company': {'name': 'Hoeger LLC', 'catchPhrase': 'Centralized empowering task-force', 'bs': 'target end-to-end models'}}]])" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "json_dict.values()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "df = pd.DataFrame.from_dict(json_dict['info'])" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnameusernameemailaddressphonewebsitecompany
01Leanne GrahamBretSincere@april.biz[{'street': 'Kulas Light', 'suite': 'Apt. 556'...1-770-736-8031 x56442hildegard.org{'name': 'Romaguera-Crona', 'catchPhrase': 'Mu...
12Ervin HowellAntonetteShanna@melissa.tv[{'street': 'Victor Plains', 'suite': 'Suite 8...010-692-6593 x09125anastasia.net{'name': 'Deckow-Crist', 'catchPhrase': 'Proac...
23Clementine BauchSamanthaNathan@yesenia.net[{'street': 'Douglas Extension', 'suite': 'Sui...1-463-123-4447ramiro.info{'name': 'Romaguera-Jacobson', 'catchPhrase': ...
34Patricia LebsackKarianneJulianne.OConner@kory.org[{'street': 'Hoeger Mall', 'suite': 'Apt. 692'...493-170-9623 x156kale.biz{'name': 'Robel-Corkery', 'catchPhrase': 'Mult...
45Chelsey DietrichKamrenLucio_Hettinger@annie.ca[{'street': 'Skiles Walks', 'suite': 'Suite 35...(254)954-1289demarco.info{'name': 'Keebler LLC', 'catchPhrase': 'User-c...
\n", + "
" + ], + "text/plain": [ + " id name username email \\\n", + "0 1 Leanne Graham Bret Sincere@april.biz \n", + "1 2 Ervin Howell Antonette Shanna@melissa.tv \n", + "2 3 Clementine Bauch Samantha Nathan@yesenia.net \n", + "3 4 Patricia Lebsack Karianne Julianne.OConner@kory.org \n", + "4 5 Chelsey Dietrich Kamren Lucio_Hettinger@annie.ca \n", + "\n", + " address phone \\\n", + "0 [{'street': 'Kulas Light', 'suite': 'Apt. 556'... 1-770-736-8031 x56442 \n", + "1 [{'street': 'Victor Plains', 'suite': 'Suite 8... 010-692-6593 x09125 \n", + "2 [{'street': 'Douglas Extension', 'suite': 'Sui... 1-463-123-4447 \n", + "3 [{'street': 'Hoeger Mall', 'suite': 'Apt. 692'... 493-170-9623 x156 \n", + "4 [{'street': 'Skiles Walks', 'suite': 'Suite 35... (254)954-1289 \n", + "\n", + " website company \n", + "0 hildegard.org {'name': 'Romaguera-Crona', 'catchPhrase': 'Mu... \n", + "1 anastasia.net {'name': 'Deckow-Crist', 'catchPhrase': 'Proac... \n", + "2 ramiro.info {'name': 'Romaguera-Jacobson', 'catchPhrase': ... \n", + "3 kale.biz {'name': 'Robel-Corkery', 'catchPhrase': 'Mult... \n", + "4 demarco.info {'name': 'Keebler LLC', 'catchPhrase': 'User-c... " + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "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.11.4" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} From cd1acaca827ea21dce30298cbc31ddbcacfaf4a1 Mon Sep 17 00:00:00 2001 From: Mojtaba Peyrovi Date: Wed, 4 Oct 2023 20:09:44 +0200 Subject: [PATCH 2/3] the way json_normalize is imported is deprecated. fixed it --- moji-codealong/lesson8/notebook.ipynb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/moji-codealong/lesson8/notebook.ipynb b/moji-codealong/lesson8/notebook.ipynb index 384abca..4b43af6 100644 --- a/moji-codealong/lesson8/notebook.ipynb +++ b/moji-codealong/lesson8/notebook.ipynb @@ -408,7 +408,10 @@ "execution_count": 18, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#from pandas.io.json import json_normalize -> pandas.io.json.json_normalize is deprecated\n", + "from pandas import json_normalize\n" + ] }, { "cell_type": "code", From ce58f11963f2540e3448967f8ae6c4c693ba0cc1 Mon Sep 17 00:00:00 2001 From: Mojtaba Peyrovi Date: Wed, 4 Oct 2023 20:12:53 +0200 Subject: [PATCH 3/3] the way json_normalize is imported is deprecated. fixed it --- moji-codealong/lesson8/notebook.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/moji-codealong/lesson8/notebook.ipynb b/moji-codealong/lesson8/notebook.ipynb index 4b43af6..edb9241 100644 --- a/moji-codealong/lesson8/notebook.ipynb +++ b/moji-codealong/lesson8/notebook.ipynb @@ -405,12 +405,12 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ - "#from pandas.io.json import json_normalize -> pandas.io.json.json_normalize is deprecated\n", - "from pandas import json_normalize\n" + "#from pandas.io.json import json_normalize -> pandas.io.json.json_normalize is deprecated. we need to directly import it from pandas\n", + "from pandas import json_normalize" ] }, {