{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "df_napping = pd.read_csv('../data/csv/napping.csv')\n", "df_napping['experiment_no'] = [int(item.replace('experiment_no_', '')) for item in df_napping.experiment_no]\n", "df_participant = pd.read_csv('../data/csv/participants.csv', sep = \";\")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1014630, 12)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_image_review_attributes = pd.read_csv('../data/csv/images_reviews_attributes.csv')\n", "df_image_review_attributes.shape" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1010152, 12)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# drop rows on image column if they are null\n", "df_image_review_attributes = df_image_review_attributes.dropna(subset=['image'])\n", "df_image_review_attributes.shape" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def write_jsonl(df, file_path):\n", " with open(file_path, 'w') as jsonlfile:\n", " for _, row in df.iterrows():\n", " # Convert each row to a JSON string and write it as a line in JSONL\n", " json_string = row.to_json()\n", " jsonlfile.write(json_string + '\\n')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "# IN THE README FILE, WE HAVE THE FOLLOWING INFORMATION:\n", "# to join participants with napping\n", "df_napping_participants = df_participant.\\\n", " merge(df_napping, on=['event_name', 'session_round_name', 'experiment_no'])\n", "\n", "write_jsonl(df_napping_participants, '../data/napping_participants/napping_participants.jsonl')\n", "\n", "# LOAD VINTAGES\n", "df_vintages = df_image_review_attributes.\\\n", " drop(columns=['image', 'review', 'experiment_id']).\\\n", " dropna(subset = ['winery_id']).\\\n", " drop_duplicates().\\\n", " astype({'year': int, 'winery_id': int})\n", "write_jsonl(df_vintages, '../data/vintages/vintages_dataset.jsonl')\n", "\n", "# LOAD IMAGES 'small'\n", "df_small = df_image_review_attributes.sample(frac = 0.1)\n", "write_jsonl(df_small, '../data/small/small_dataset.jsonl')\n", "# df_napping\n", "# df_participant\n", "\n", "# LOAD IMAGES 'all'\n", "write_jsonl(df_image_review_attributes, '../data/all/all_dataset.jsonl')\n", "# df_napping\n", "# df_participant\n", "\n", "# LOAD ONLY IMAGE-REVIEW of PROFILED WINES IN THE WINE TASTING EXPERIMENT\n", "df_image_review_of_experiment = df_image_review_attributes.dropna(subset = ['experiment_id']).\\\n", " astype({'experiment_id': int, 'year': int})\n", "write_jsonl(df_image_review_of_experiment, '../data/wt_session/wt_session.jsonl')\n", "# df_napping\n", "# df_participant\n" ] }, { "cell_type": "code", "execution_count": 8, "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", "
event_namesession_round_nameexperiment_noround_idparticipant_idexperiment_idcoor1coor2color
0experiment_vivino_31_03round_1_images0125410617282882red
1experiment_vivino_31_03round_1_images0125411217882060light-purple
2experiment_vivino_31_03round_1_images0125410910041972purple
3experiment_vivino_31_03round_1_images0125411110151760blue
\n", "
" ], "text/plain": [ " event_name session_round_name experiment_no round_id \\\n", "0 experiment_vivino_31_03 round_1_images 0 1 \n", "1 experiment_vivino_31_03 round_1_images 0 1 \n", "2 experiment_vivino_31_03 round_1_images 0 1 \n", "3 experiment_vivino_31_03 round_1_images 0 1 \n", "\n", " participant_id experiment_id coor1 coor2 color \n", "0 254 106 1728 2882 red \n", "1 254 112 1788 2060 light-purple \n", "2 254 109 1004 1972 purple \n", "3 254 111 1015 1760 blue " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_napping_participants.head(4)" ] }, { "cell_type": "code", "execution_count": 9, "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", "
vintage_idyearwinery_idwine_alcoholcountryregionpriceratinggrape
175514696762018247919NaNItalyAbruzzo22.264.3Sangiovese
22301562638482018208014.0United StatesNapa Valley13.864.0Pinot Noir
387115617765020181822413.5ItalySalento19.464.0Primitivo
431920161520201521576214.0FranceSaint-Émilion Grand Cru23.664.1Merlot
\n", "
" ], "text/plain": [ " vintage_id year winery_id wine_alcohol country \\\n", "1755 1469676 2018 247919 NaN Italy \n", "2230 156263848 2018 2080 14.0 United States \n", "3871 156177650 2018 18224 13.5 Italy \n", "4319 20161520 2015 215762 14.0 France \n", "\n", " region price rating grape \n", "1755 Abruzzo 22.26 4.3 Sangiovese \n", "2230 Napa Valley 13.86 4.0 Pinot Noir \n", "3871 Salento 19.46 4.0 Primitivo \n", "4319 Saint-Émilion Grand Cru 23.66 4.1 Merlot " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_vintages.head(4)" ] }, { "cell_type": "code", "execution_count": 10, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
vintage_idimagereviewexperiment_idyearwinery_idwine_alcoholcountryregionpriceratinggrape
429091150905918p/SPYooSq3SrCroz8QOE19lQ.jpgMedium purple coloured. Medium intensity, blac...NaNNaNNaNNaNNaNNaNNaNNaNNaN
242022155500756p/aZYgB_ioT_SeSf8NZNndaA.jpgLPV Lyon 2, Feb 2019: light gold, quite intens...NaNNaNNaNNaNNaNNaNNaNNaNNaN
34614156712592p/6aNPhRyFRZmNPTD1ZgOEnQ.jpgNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
124131159619405p/8vP7aXeXRIuZ_ln84WuAoA.jpgIntense aroma and flavors, nicely matured, ear...NaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " vintage_id image \\\n", "429091 150905918 p/SPYooSq3SrCroz8QOE19lQ.jpg \n", "242022 155500756 p/aZYgB_ioT_SeSf8NZNndaA.jpg \n", "34614 156712592 p/6aNPhRyFRZmNPTD1ZgOEnQ.jpg \n", "124131 159619405 p/8vP7aXeXRIuZ_ln84WuAoA.jpg \n", "\n", " review experiment_id \\\n", "429091 Medium purple coloured. Medium intensity, blac... NaN \n", "242022 LPV Lyon 2, Feb 2019: light gold, quite intens... NaN \n", "34614 NaN NaN \n", "124131 Intense aroma and flavors, nicely matured, ear... NaN \n", "\n", " year winery_id wine_alcohol country region price rating grape \n", "429091 NaN NaN NaN NaN NaN NaN NaN NaN \n", "242022 NaN NaN NaN NaN NaN NaN NaN NaN \n", "34614 NaN NaN NaN NaN NaN NaN NaN NaN \n", "124131 NaN NaN NaN NaN NaN NaN NaN NaN " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_small.head(4)" ] }, { "cell_type": "code", "execution_count": 11, "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", " \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", " \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", "
vintage_idimagereviewexperiment_idyearwinery_idwine_alcoholcountryregionpriceratinggrape
0150301706p/iVoa6qR6TSKjLeb1RoHWtQ.jpgНичего особого в нем не нашел. В меру сухое, в...NaNNaNNaNNaNNaNNaNNaNNaNNaN
1159555436p/e2W_085qRbCQbZJVp_tzHA.jpgNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
2146958680p/DdLNo35SRiCMxpoKTiEXyQ.jpgNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
32014691p/vi-1ygw7RXCM6Pnwx9C6CA.jpg3,3/5. Белая Риоха. Бленд на основе виуры (75%...NaNNaNNaNNaNNaNNaNNaNNaNNaN
4153305559p/1pjborIfR1Wdlr35jEHbtA.jpgParfum! Super frumos!NaNNaNNaNNaNNaNNaNNaNNaNNaN
5162913950p/kDz5LBlFRz2wb61xaMj_Dw.jpgBom vinhoNaNNaNNaNNaNNaNNaNNaNNaNNaN
614230455p/EJQLq-qLShSP-uf2Tg-G1g.jpgNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
7159888939p/MhhKQteWSXW0gYUNnvHs6A.jpgV nice whitrNaNNaNNaNNaNNaNNaNNaNNaNNaN
83261951p/fdsdbl6XR2ynvoQnNYLXQQ.jpgGreat label and ok tasting. Not the best but n...NaNNaNNaNNaNNaNNaNNaNNaNNaN
932363311p/BQkoD9sXQi-EIk3e2cG-YA.jpgNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "
" ], "text/plain": [ " vintage_id image \\\n", "0 150301706 p/iVoa6qR6TSKjLeb1RoHWtQ.jpg \n", "1 159555436 p/e2W_085qRbCQbZJVp_tzHA.jpg \n", "2 146958680 p/DdLNo35SRiCMxpoKTiEXyQ.jpg \n", "3 2014691 p/vi-1ygw7RXCM6Pnwx9C6CA.jpg \n", "4 153305559 p/1pjborIfR1Wdlr35jEHbtA.jpg \n", "5 162913950 p/kDz5LBlFRz2wb61xaMj_Dw.jpg \n", "6 14230455 p/EJQLq-qLShSP-uf2Tg-G1g.jpg \n", "7 159888939 p/MhhKQteWSXW0gYUNnvHs6A.jpg \n", "8 3261951 p/fdsdbl6XR2ynvoQnNYLXQQ.jpg \n", "9 32363311 p/BQkoD9sXQi-EIk3e2cG-YA.jpg \n", "\n", " review experiment_id year \\\n", "0 Ничего особого в нем не нашел. В меру сухое, в... NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 3,3/5. Белая Риоха. Бленд на основе виуры (75%... NaN NaN \n", "4 Parfum! Super frumos! NaN NaN \n", "5 Bom vinho NaN NaN \n", "6 NaN NaN NaN \n", "7 V nice whitr NaN NaN \n", "8 Great label and ok tasting. Not the best but n... NaN NaN \n", "9 NaN NaN NaN \n", "\n", " winery_id wine_alcohol country region price rating grape \n", "0 NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN \n", "3 NaN NaN NaN NaN NaN NaN NaN \n", "4 NaN NaN NaN NaN NaN NaN NaN \n", "5 NaN NaN NaN NaN NaN NaN NaN \n", "6 NaN NaN NaN NaN NaN NaN NaN \n", "7 NaN NaN NaN NaN NaN NaN NaN \n", "8 NaN NaN NaN NaN NaN NaN NaN \n", "9 NaN NaN NaN NaN NaN NaN NaN " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_image_review_attributes.head(10)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "import json" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ALL" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "pd.DataFrame([item.replace('p/', '') for item in df_image_review_attributes.image if item is not None]).\\\n", " to_csv('../data/csv/all.csv', index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## SMALL" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "# read small_dataset.jsonl \n", "with open('../data/small/small_dataset.jsonl') as json_file:\n", " data = json_file.readlines()\n", " data = [json.loads(line) for line in data] # convert string to dict format\n", "\n", "import pandas as pd\n", "small_df = pd.DataFrame(data)\n", "\n", "\n", "# write the image column to a csv file\n", "pd.DataFrame([item.replace('p/', '') for item in small_df.image if item is not None]).\\\n", " to_csv('../data/csv/small_images.csv', index=False)\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## WT_SESSION" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "# read small_dataset.jsonl \n", "with open('../data/jsonl/wt_session.jsonl') as json_file:\n", " data = json_file.readlines()\n", " data = [json.loads(line) for line in data] # convert string to dict format\n", "\n", "import pandas as pd\n", "small_df = pd.DataFrame(data)\n", "\n", "# write the image column to a csv file\n", "pd.DataFrame([item.replace('p/', '') for item in small_df.image if item is not None]).\\\n", " to_csv('../data/csv/wt_session.jsonl_images.csv', index=False)\n", " " ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "# read small_dataset.jsonl \n", "with open('../data/jsonl/wt_session.jsonl') as json_file:\n", " data = json_file.readlines()\n", " data = [json.loads(line) for line in data] # convert string to dict format\n", "\n", "import pandas as pd\n", "wt_session = pd.DataFrame(data)\n" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "# drop rows on image column if they are null\n", "wt_session_no_nall = wt_session.dropna(subset=['image'])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(45339, 12)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "wt_session_no_nall.shape" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "# convert small_df_no_nall into jsonl format\n", "write_jsonl(wt_session_no_nall, '../data/wt_session/wt_session_no_null.jsonl')" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "# read the json file\n", "with open('/Users/alka/Devel/GIT_LFS_SKIP_SMUDGE=1/metadata/all/all_dataset.jsonl') as json_file:\n", " data = json_file.readlines()\n", " data = [json.loads(line) for line in data] # convert string to dict format" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "litegrave", "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.10.5" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }