{ "cells": [ { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "\n", "import pandas as pd\n", "import numpy as np\n", "\n", "# read csv file\n", "df = pd.read_csv('2000s_normalized.csv')" ] }, { "cell_type": "code", "execution_count": 42, "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", "
idcontentnormalized_tweet
01Spend your weekend morning with a Ham, Egg, an...Spend your weekend morning with a Ham , Egg , ...
12Watch rapper <mention> freestyle for over an H...Watch rapper <mention> freestyle for over an H...
23Canadian Armenian community demands ban on mil...Canadian Armenian community demands ban on mil...
341st in Europe to be devastated by COVID-19, It...1st in Europe to be devastated by COVID - 19 ,...
45Congratulations to Pauletha Butts of <mention>...Congratulations to Pauletha Butts of <mention>...
57LASU Celebrates New Dawn Of Unbroken Peace As ...LASU Celebrates New Dawn Of Unbroken Peace As ...
69A 95-year-old World War II veteran says he was...A 95 - year-old World War II veteran says he w...
710Nicholas Hoult, Charlize Theron, and Aisha Tyl...Nicholas Hoult , Charlize Theron , and Aisha T...
811.<mention> takes the stage at #BHUSA to talk a.... <mention> takes the stage at #BHUSA to talk ...
912#NetZeroHomes: learn the best way to get to ze...#NetZeroHomes : learn the best way to get to z...
1015Survivors of the Parkland shooting were awarde...Survivors of the Parkland shooting were awarde...
1119Linda Ikeji Partners ECOBANK To Empower Young ...Linda Ikeji Partners ECOBANK To Empower Young ...
1220LOOK: World-class singers Darren Espanto <ment...LOOK : World-class singers Darren Espanto <men...
1321.<mention> is investing $1.5 billion into next.... <mention> is investing $ 1.5 billion into ne...
1422Supreme Court Chief Justice John Roberts makes...Supreme Court Chief Justice John Roberts makes...
1523Tournaments come and go, but the pictures are ...Tournaments come and go , but the pictures are...
1624Twitter suspends 70 pro-Bloomberg accounts for...Twitter suspends 70 pro-Bloomberg accounts for...
1725Many people are understandably anxious to get ...Many people are understandably anxious to get ...
1827ALSO NOW (yes it's wild here today): Sen Merkl...ALSO NOW ( yes it 's wild here today ): Sen Me...
1928We got a sneak peek at Star Wars Jedi: Fallen ...We got a sneak peek at Star Wars Jedi : Fallen...
\n", "
" ], "text/plain": [ " id content \\\n", "0 1 Spend your weekend morning with a Ham, Egg, an... \n", "1 2 Watch rapper freestyle for over an H... \n", "2 3 Canadian Armenian community demands ban on mil... \n", "3 4 1st in Europe to be devastated by COVID-19, It... \n", "4 5 Congratulations to Pauletha Butts of ... \n", "5 7 LASU Celebrates New Dawn Of Unbroken Peace As ... \n", "6 9 A 95-year-old World War II veteran says he was... \n", "7 10 Nicholas Hoult, Charlize Theron, and Aisha Tyl... \n", "8 11 . takes the stage at #BHUSA to talk a... \n", "9 12 #NetZeroHomes: learn the best way to get to ze... \n", "10 15 Survivors of the Parkland shooting were awarde... \n", "11 19 Linda Ikeji Partners ECOBANK To Empower Young ... \n", "12 20 LOOK: World-class singers Darren Espanto is investing $1.5 billion into next... \n", "14 22 Supreme Court Chief Justice John Roberts makes... \n", "15 23 Tournaments come and go, but the pictures are ... \n", "16 24 Twitter suspends 70 pro-Bloomberg accounts for... \n", "17 25 Many people are understandably anxious to get ... \n", "18 27 ALSO NOW (yes it's wild here today): Sen Merkl... \n", "19 28 We got a sneak peek at Star Wars Jedi: Fallen ... \n", "\n", " normalized_tweet \n", "0 Spend your weekend morning with a Ham , Egg , ... \n", "1 Watch rapper freestyle for over an H... \n", "2 Canadian Armenian community demands ban on mil... \n", "3 1st in Europe to be devastated by COVID - 19 ,... \n", "4 Congratulations to Pauletha Butts of ... \n", "5 LASU Celebrates New Dawn Of Unbroken Peace As ... \n", "6 A 95 - year-old World War II veteran says he w... \n", "7 Nicholas Hoult , Charlize Theron , and Aisha T... \n", "8 . takes the stage at #BHUSA to talk ... \n", "9 #NetZeroHomes : learn the best way to get to z... \n", "10 Survivors of the Parkland shooting were awarde... \n", "11 Linda Ikeji Partners ECOBANK To Empower Young ... \n", "12 LOOK : World-class singers Darren Espanto is investing $ 1.5 billion into ne... \n", "14 Supreme Court Chief Justice John Roberts makes... \n", "15 Tournaments come and go , but the pictures are... \n", "16 Twitter suspends 70 pro-Bloomberg accounts for... \n", "17 Many people are understandably anxious to get ... \n", "18 ALSO NOW ( yes it 's wild here today ): Sen Me... \n", "19 We got a sneak peek at Star Wars Jedi : Fallen... " ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# drop content column\n", "\n", "# drop Unnamed: 0 column\n", "df = df.drop(columns=['Unnamed: 0'])\n", "df.head(20)" ] }, { "cell_type": "code", "execution_count": 43, "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", "
idnormalized_tweet
01Spend your weekend morning with a Ham , Egg , ...
12Watch rapper <mention> freestyle for over an H...
23Canadian Armenian community demands ban on mil...
341st in Europe to be devastated by COVID - 19 ,...
45Congratulations to Pauletha Butts of <mention>...
57LASU Celebrates New Dawn Of Unbroken Peace As ...
69A 95 - year-old World War II veteran says he w...
710Nicholas Hoult , Charlize Theron , and Aisha T...
811. <mention> takes the stage at #BHUSA to talk ...
912#NetZeroHomes : learn the best way to get to z...
1015Survivors of the Parkland shooting were awarde...
1119Linda Ikeji Partners ECOBANK To Empower Young ...
1220LOOK : World-class singers Darren Espanto <men...
1321. <mention> is investing $ 1.5 billion into ne...
1422Supreme Court Chief Justice John Roberts makes...
1523Tournaments come and go , but the pictures are...
1624Twitter suspends 70 pro-Bloomberg accounts for...
1725Many people are understandably anxious to get ...
1827ALSO NOW ( yes it 's wild here today ): Sen Me...
1928We got a sneak peek at Star Wars Jedi : Fallen...
\n", "
" ], "text/plain": [ " id normalized_tweet\n", "0 1 Spend your weekend morning with a Ham , Egg , ...\n", "1 2 Watch rapper freestyle for over an H...\n", "2 3 Canadian Armenian community demands ban on mil...\n", "3 4 1st in Europe to be devastated by COVID - 19 ,...\n", "4 5 Congratulations to Pauletha Butts of ...\n", "5 7 LASU Celebrates New Dawn Of Unbroken Peace As ...\n", "6 9 A 95 - year-old World War II veteran says he w...\n", "7 10 Nicholas Hoult , Charlize Theron , and Aisha T...\n", "8 11 . takes the stage at #BHUSA to talk ...\n", "9 12 #NetZeroHomes : learn the best way to get to z...\n", "10 15 Survivors of the Parkland shooting were awarde...\n", "11 19 Linda Ikeji Partners ECOBANK To Empower Young ...\n", "12 20 LOOK : World-class singers Darren Espanto is investing $ 1.5 billion into ne...\n", "14 22 Supreme Court Chief Justice John Roberts makes...\n", "15 23 Tournaments come and go , but the pictures are...\n", "16 24 Twitter suspends 70 pro-Bloomberg accounts for...\n", "17 25 Many people are understandably anxious to get ...\n", "18 27 ALSO NOW ( yes it 's wild here today ): Sen Me...\n", "19 28 We got a sneak peek at Star Wars Jedi : Fallen..." ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# drop content column and rename normalized_content to content\n", "df = df.drop(columns=['content'])\n", "\n", "df.head(20)" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "df = df.rename(columns={'normalized_tweet': 'caption'})" ] }, { "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idcaption
13781961Looking for great monsoon getaways #ThisWeeken...
13791964Cisco launches Meraki Insight - creating fast ...
13801967💅🏾 Survived on crumbs for 35 years , worked my...
13811969Sule Hands Over Building Complex To Federal Va...
13821971Court Sentences Man , 21 , To 8 Months Communi...
13831972Hear about Cisco Umbrella from 335 verified Te...
13841975Shashi , who was part of the core team that le...
13851976Will be phoning you at #NewYear #Happy2019 - a...
13861977Here 's where <mention> and <mention> sit foll...
13871980Best players in the World according to Gary Li...
13881983The man behind the USS Cole attack that killed...
13891986Trump is on a Nixonian collision course with t...
13901987#Cisco #SDWAN securely connects everything eve...
13911989How Africa Risks Reeling From A Health Crisis ...
13921990Women kayakers win Canada 's 1st Pan Am Games ...
13931991IT'S OFFICIAL : Arsenal have confirmed that Da...
13941995Messi Masterclass On Display As Barcelona Thra...
13951997Are you under constant pressure to connect use...
13961998Shun Ethnic Prejudice , Religious Intolerance ...
13972000Encrypted On-Prem Connections to Public Clouds...
\n", "
" ], "text/plain": [ " id caption\n", "1378 1961 Looking for great monsoon getaways #ThisWeeken...\n", "1379 1964 Cisco launches Meraki Insight - creating fast ...\n", "1380 1967 💅🏾 Survived on crumbs for 35 years , worked my...\n", "1381 1969 Sule Hands Over Building Complex To Federal Va...\n", "1382 1971 Court Sentences Man , 21 , To 8 Months Communi...\n", "1383 1972 Hear about Cisco Umbrella from 335 verified Te...\n", "1384 1975 Shashi , who was part of the core team that le...\n", "1385 1976 Will be phoning you at #NewYear #Happy2019 - a...\n", "1386 1977 Here 's where and sit foll...\n", "1387 1980 Best players in the World according to Gary Li...\n", "1388 1983 The man behind the USS Cole attack that killed...\n", "1389 1986 Trump is on a Nixonian collision course with t...\n", "1390 1987 #Cisco #SDWAN securely connects everything eve...\n", "1391 1989 How Africa Risks Reeling From A Health Crisis ...\n", "1392 1990 Women kayakers win Canada 's 1st Pan Am Games ...\n", "1393 1991 IT'S OFFICIAL : Arsenal have confirmed that Da...\n", "1394 1995 Messi Masterclass On Display As Barcelona Thra...\n", "1395 1997 Are you under constant pressure to connect use...\n", "1396 1998 Shun Ethnic Prejudice , Religious Intolerance ...\n", "1397 2000 Encrypted On-Prem Connections to Public Clouds..." ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.tail(20)" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "# Now there is a folder named images containing {id}.jpg files for each id in the dataset (i.e. 1.jpg, 2.jpg, etc.). \n", "# create a dataset containing the image itself and the normalized content text for each id. export to parquet file\n", "\n", "# convert each image into bytes array and store in a new column\n", "\n", "def convert_to_bytes(img_path):\n", " dict = {\"bytes\": [], \"path\": None}\n", " with open(img_path, 'rb') as f:\n", " img_bytes = f.read()\n", "\n", " dict = {\"bytes\": [], \"path\": None}\n", " dict[\"bytes\"] = img_bytes\n", " return dict\n", "\n", "\n", "# create a new column containing the image bytes and store in this format # {\"bytes\": [255,216,2....,34], \"path\": null}\n", "df['image'] = df['id'].apply(lambda x: convert_to_bytes('images/' + str(x) + '.jpg'))\n", "\n", "\n", "# drop the id column\n", "df = df.drop(columns=['id'])\n", "\n", "# export to parquet file\n", "df.to_parquet('2000_tweet_image_caption.parquet')\n", "\n", "\n", "\n", "\n", "\n" ] } ], "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" } }, "nbformat": 4, "nbformat_minor": 2 }