{
"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",
" event_name | \n",
" session_round_name | \n",
" experiment_no | \n",
" round_id | \n",
" participant_id | \n",
" experiment_id | \n",
" coor1 | \n",
" coor2 | \n",
" color | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" experiment_vivino_31_03 | \n",
" round_1_images | \n",
" 0 | \n",
" 1 | \n",
" 254 | \n",
" 106 | \n",
" 1728 | \n",
" 2882 | \n",
" red | \n",
"
\n",
" \n",
" 1 | \n",
" experiment_vivino_31_03 | \n",
" round_1_images | \n",
" 0 | \n",
" 1 | \n",
" 254 | \n",
" 112 | \n",
" 1788 | \n",
" 2060 | \n",
" light-purple | \n",
"
\n",
" \n",
" 2 | \n",
" experiment_vivino_31_03 | \n",
" round_1_images | \n",
" 0 | \n",
" 1 | \n",
" 254 | \n",
" 109 | \n",
" 1004 | \n",
" 1972 | \n",
" purple | \n",
"
\n",
" \n",
" 3 | \n",
" experiment_vivino_31_03 | \n",
" round_1_images | \n",
" 0 | \n",
" 1 | \n",
" 254 | \n",
" 111 | \n",
" 1015 | \n",
" 1760 | \n",
" blue | \n",
"
\n",
" \n",
"
\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",
" vintage_id | \n",
" year | \n",
" winery_id | \n",
" wine_alcohol | \n",
" country | \n",
" region | \n",
" price | \n",
" rating | \n",
" grape | \n",
"
\n",
" \n",
" \n",
" \n",
" 1755 | \n",
" 1469676 | \n",
" 2018 | \n",
" 247919 | \n",
" NaN | \n",
" Italy | \n",
" Abruzzo | \n",
" 22.26 | \n",
" 4.3 | \n",
" Sangiovese | \n",
"
\n",
" \n",
" 2230 | \n",
" 156263848 | \n",
" 2018 | \n",
" 2080 | \n",
" 14.0 | \n",
" United States | \n",
" Napa Valley | \n",
" 13.86 | \n",
" 4.0 | \n",
" Pinot Noir | \n",
"
\n",
" \n",
" 3871 | \n",
" 156177650 | \n",
" 2018 | \n",
" 18224 | \n",
" 13.5 | \n",
" Italy | \n",
" Salento | \n",
" 19.46 | \n",
" 4.0 | \n",
" Primitivo | \n",
"
\n",
" \n",
" 4319 | \n",
" 20161520 | \n",
" 2015 | \n",
" 215762 | \n",
" 14.0 | \n",
" France | \n",
" Saint-Émilion Grand Cru | \n",
" 23.66 | \n",
" 4.1 | \n",
" Merlot | \n",
"
\n",
" \n",
"
\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",
" vintage_id | \n",
" image | \n",
" review | \n",
" experiment_id | \n",
" year | \n",
" winery_id | \n",
" wine_alcohol | \n",
" country | \n",
" region | \n",
" price | \n",
" rating | \n",
" grape | \n",
"
\n",
" \n",
" \n",
" \n",
" 429091 | \n",
" 150905918 | \n",
" p/SPYooSq3SrCroz8QOE19lQ.jpg | \n",
" Medium purple coloured. Medium intensity, blac... | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 242022 | \n",
" 155500756 | \n",
" p/aZYgB_ioT_SeSf8NZNndaA.jpg | \n",
" LPV Lyon 2, Feb 2019: light gold, quite intens... | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 34614 | \n",
" 156712592 | \n",
" p/6aNPhRyFRZmNPTD1ZgOEnQ.jpg | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 124131 | \n",
" 159619405 | \n",
" p/8vP7aXeXRIuZ_ln84WuAoA.jpg | \n",
" Intense aroma and flavors, nicely matured, ear... | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
"
\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",
" vintage_id | \n",
" image | \n",
" review | \n",
" experiment_id | \n",
" year | \n",
" winery_id | \n",
" wine_alcohol | \n",
" country | \n",
" region | \n",
" price | \n",
" rating | \n",
" grape | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 150301706 | \n",
" p/iVoa6qR6TSKjLeb1RoHWtQ.jpg | \n",
" Ничего особого в нем не нашел. В меру сухое, в... | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 1 | \n",
" 159555436 | \n",
" p/e2W_085qRbCQbZJVp_tzHA.jpg | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 2 | \n",
" 146958680 | \n",
" p/DdLNo35SRiCMxpoKTiEXyQ.jpg | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 3 | \n",
" 2014691 | \n",
" p/vi-1ygw7RXCM6Pnwx9C6CA.jpg | \n",
" 3,3/5. Белая Риоха. Бленд на основе виуры (75%... | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 4 | \n",
" 153305559 | \n",
" p/1pjborIfR1Wdlr35jEHbtA.jpg | \n",
" Parfum! Super frumos! | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 5 | \n",
" 162913950 | \n",
" p/kDz5LBlFRz2wb61xaMj_Dw.jpg | \n",
" Bom vinho | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 6 | \n",
" 14230455 | \n",
" p/EJQLq-qLShSP-uf2Tg-G1g.jpg | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 7 | \n",
" 159888939 | \n",
" p/MhhKQteWSXW0gYUNnvHs6A.jpg | \n",
" V nice whitr | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 8 | \n",
" 3261951 | \n",
" p/fdsdbl6XR2ynvoQnNYLXQQ.jpg | \n",
" Great label and ok tasting. Not the best but n... | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" 9 | \n",
" 32363311 | \n",
" p/BQkoD9sXQi-EIk3e2cG-YA.jpg | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
"
\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
}