{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "0c875ce0-80ad-42f3-af90-9bb1c1e53858", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['CO2', 'CSR', 'ESG', 'SDG', 'bio', 'carb', 'challeng', 'chang', 'clean', 'climate', 'eco', 'emissions', 'environment', 'future', 'garbage', 'green', 'methanol', 'mission', 'neutral', 'ocean', 'planet', 'plastic', 'recycling', 'reduc', 'responsib', 'sulphur', 'sustainab', 'zero']\n" ] } ], "source": [ "# load list of words related to sustainability\n", "path = 'sustainability_words.txt'\n", "word_list = list()\n", "with open(path, 'r') as f:\n", " for line in f.readlines():\n", " word_list.append(line.replace('\\n', ''))\n", "\n", "word_list.sort()\n", "print(word_list)" ] }, { "cell_type": "code", "execution_count": 2, "id": "99837ffc-0eb7-4e89-87e5-eedbe35219bc", "metadata": { "tags": [] }, "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", "
wordcountsratio
0maersk32070.04001
1is10250.01279
2more9890.01234
3here8250.01029
4trade6420.00801
............
10920ritzau10.00001
10921baan10.00001
10922indiabased10.00001
10923occurs10.00001
10924multicarrier10.00001
\n", "

10925 rows × 3 columns

\n", "
" ], "text/plain": [ " word counts ratio\n", "0 maersk 3207 0.04001\n", "1 is 1025 0.01279\n", "2 more 989 0.01234\n", "3 here 825 0.01029\n", "4 trade 642 0.00801\n", "... ... ... ...\n", "10920 ritzau 1 0.00001\n", "10921 baan 1 0.00001\n", "10922 indiabased 1 0.00001\n", "10923 occurs 1 0.00001\n", "10924 multicarrier 1 0.00001\n", "\n", "[10925 rows x 3 columns]" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# load word counts from tweets\n", "import pandas as pd\n", "\n", "word_df = pd.read_csv('word_count.csv', index_col=0)\n", "\n", "word_df" ] }, { "cell_type": "code", "execution_count": 3, "id": "57e749a9-3401-4cb5-98b0-ad68098bf5b4", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['become', 'becomes', 'becoming', 'blueeconomy', 'changed', 'chinaeconomy', 'deconsolidation', 'decorated', 'decoupling', 'ecommerce', 'ecommercelogistics', 'economia', 'economic', 'economically', 'economicgrowth', 'economictimes', 'economies', 'economist', 'economistimpact', 'economy', 'environments', 'fairfuture4seafarers', 'mclean', 'portrecord', 'recognise', 'recognised', 'recognising', 'recognition', 'recognized', 'record', 'recorded', 'records', 'recovery', 'second', 'secondbusiest', 'secondgeneration', 'secondlargest', 'seconds', 'shetradesglobal', 'socioeconomic', 'telecoms', 'theeconomist', 'transoceanic', 'unchanged', 'worldrecord']\n" ] } ], "source": [ "# load ignore list\n", "ignore_list = list()\n", "path = 'ignore_words.txt'\n", "with open(path, 'r') as f:\n", " for line in f.readlines():\n", " ignore_list.append(line.replace('\\n', ''))\n", " \n", "ignore_list.sort()\n", "print(ignore_list)" ] }, { "cell_type": "code", "execution_count": 4, "id": "f2f37c6b-cb1f-4c71-aa24-9601d5bfe7b8", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CO2\n", "['co2', 'co2neutral', 'co2emission']\n", "3390.0\n", "2275.0\n" ] } ], "source": [ "import numpy as np\n", "\n", "match_word_list = list()\n", "mean_idx_list = list()\n", "sigma_idx_list = list()\n", "for i, word in enumerate(word_list):\n", " # find index of matching words\n", " contains_word_mask = word_df['word'].str.contains(word.lower())==True\n", " counts_above_limit_mask = word_df['counts'].gt(1)\n", " match_mask = contains_word_mask & counts_above_limit_mask\n", " match_idx_list = word_df[match_mask].index.tolist()\n", " # remove indices of unwanted words\n", " remove_idx_list = list()\n", " for idx in match_idx_list:\n", " match_word = word_df.loc[idx, 'word']\n", " if match_word in ignore_list:\n", " remove_idx_list.append(idx)\n", " for idx in remove_idx_list:\n", " match_idx_list.remove(idx)\n", " # store matched words\n", " match_word_list.append(list())\n", " for idx in match_idx_list:\n", " match_word = word_df.loc[idx, 'word']\n", " match_word_list[i].append(match_word)\n", " # calculate mean and std of word ranking from located indices\n", " mu = np.array(match_idx_list).mean().round()\n", " mean_idx_list.append(mu)\n", " sigma = np.array(match_idx_list).std().round()\n", " sigma_idx_list.append(sigma)\n", "\n", "# show example of results\n", "idx = 0\n", "print(word_list[idx])\n", "print(match_word_list[idx])\n", "print(mean_idx_list[idx])\n", "print(sigma_idx_list[idx])" ] }, { "cell_type": "code", "execution_count": 5, "id": "f825653d-6c43-46bc-bc11-f9b8f4de5414", "metadata": { "tags": [] }, "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rootmean_rankingstd_rankingword_matches
0CO23390.02275.0[co2, co2neutral, co2emission]
1CSR1371.00.0[csr]
2ESG636.00.0[esg]
3SDG423.00.0[sdgs]
4bio3687.01274.0[biofuel, biofuels, biohuts, biodiversity]
5carb1952.01526.0[decarbonisation, carbon, decarbonization, car...
6challeng420.0264.0[challenges, challenge, challenging]
7chang2148.01667.0[change, changing, climatechange, changes, exc...
8clean1695.0837.0[theoceancleanup, cleanup, clean, cleanseas, o...
9climate3046.02095.0[climateaction, climate, climatechange, climat...
10eco3074.01269.0[ecosystem, eco, maerskecodelivery, ecofriendl...
11emissions2925.02046.0[emissions, carbonemissions, zeroemissions]
12environment2391.01574.0[environment, environmental, unenvironment, en...
13future1770.01684.0[future, futureproofing]
14garbage1808.0612.0[garbage, greatpacificgarbagepatch]
15green2393.01158.0[green, greenfuels, greener, greenfuel, greent...
16methanol1700.01044.0[methanol, emethanol]
17mission3247.01950.0[emissions, mission, eucommission, carbonemiss...
18neutral2382.01798.0[neutral, carbonneutral, neutrality, co2neutral]
19ocean2169.01629.0[ocean, theoceancleanup, oceans, oceanplastic,...
20planet1295.00.0[planet]
21plastic2320.01490.0[plastic, oceanplastic, plasticwaste, plasticp...
22recycling860.0154.0[recycling, shiprecycling]
23reduc1242.0965.0[reduce, reducing, reduced, reduction, reducti...
24responsib1889.01135.0[responsible, responsibility, responsibly, res...
25sulphur2828.01772.0[sulphur, lowsulphur]
26sustainab1527.01873.0[sustainability, sustainable, sustainableshipp...
27zero2977.01646.0[zero, netzero, zerocarbon, zerocarbonship, ze...
\n", "
" ], "text/plain": [ " root mean_ranking std_ranking \n", "0 CO2 3390.0 2275.0 \\\n", "1 CSR 1371.0 0.0 \n", "2 ESG 636.0 0.0 \n", "3 SDG 423.0 0.0 \n", "4 bio 3687.0 1274.0 \n", "5 carb 1952.0 1526.0 \n", "6 challeng 420.0 264.0 \n", "7 chang 2148.0 1667.0 \n", "8 clean 1695.0 837.0 \n", "9 climate 3046.0 2095.0 \n", "10 eco 3074.0 1269.0 \n", "11 emissions 2925.0 2046.0 \n", "12 environment 2391.0 1574.0 \n", "13 future 1770.0 1684.0 \n", "14 garbage 1808.0 612.0 \n", "15 green 2393.0 1158.0 \n", "16 methanol 1700.0 1044.0 \n", "17 mission 3247.0 1950.0 \n", "18 neutral 2382.0 1798.0 \n", "19 ocean 2169.0 1629.0 \n", "20 planet 1295.0 0.0 \n", "21 plastic 2320.0 1490.0 \n", "22 recycling 860.0 154.0 \n", "23 reduc 1242.0 965.0 \n", "24 responsib 1889.0 1135.0 \n", "25 sulphur 2828.0 1772.0 \n", "26 sustainab 1527.0 1873.0 \n", "27 zero 2977.0 1646.0 \n", "\n", " word_matches \n", "0 [co2, co2neutral, co2emission] \n", "1 [csr] \n", "2 [esg] \n", "3 [sdgs] \n", "4 [biofuel, biofuels, biohuts, biodiversity] \n", "5 [decarbonisation, carbon, decarbonization, car... \n", "6 [challenges, challenge, challenging] \n", "7 [change, changing, climatechange, changes, exc... \n", "8 [theoceancleanup, cleanup, clean, cleanseas, o... \n", "9 [climateaction, climate, climatechange, climat... \n", "10 [ecosystem, eco, maerskecodelivery, ecofriendl... \n", "11 [emissions, carbonemissions, zeroemissions] \n", "12 [environment, environmental, unenvironment, en... \n", "13 [future, futureproofing] \n", "14 [garbage, greatpacificgarbagepatch] \n", "15 [green, greenfuels, greener, greenfuel, greent... \n", "16 [methanol, emethanol] \n", "17 [emissions, mission, eucommission, carbonemiss... \n", "18 [neutral, carbonneutral, neutrality, co2neutral] \n", "19 [ocean, theoceancleanup, oceans, oceanplastic,... \n", "20 [planet] \n", "21 [plastic, oceanplastic, plasticwaste, plasticp... \n", "22 [recycling, shiprecycling] \n", "23 [reduce, reducing, reduced, reduction, reducti... \n", "24 [responsible, responsibility, responsibly, res... \n", "25 [sulphur, lowsulphur] \n", "26 [sustainability, sustainable, sustainableshipp... \n", "27 [zero, netzero, zerocarbon, zerocarbonship, ze... " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.DataFrame({\n", " 'root': word_list,\n", " 'mean_ranking': mean_idx_list,\n", " 'std_ranking': sigma_idx_list,\n", " 'word_matches': match_word_list\n", "})\n", "\n", "df" ] }, { "cell_type": "code", "execution_count": 6, "id": "c4ea948f-66f6-405d-8b35-b390b1b3e4a7", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rootmean_rankingstd_rankingword_matches
0challeng420.0264.0[challenges, challenge, challenging]
1SDG423.00.0[sdgs]
2ESG636.00.0[esg]
3recycling860.0154.0[recycling, shiprecycling]
4reduc1242.0965.0[reduce, reducing, reduced, reduction, reducti...
5planet1295.00.0[planet]
6CSR1371.00.0[csr]
7sustainab1527.01873.0[sustainability, sustainable, sustainableshipp...
8clean1695.0837.0[theoceancleanup, cleanup, clean, cleanseas, o...
9methanol1700.01044.0[methanol, emethanol]
10future1770.01684.0[future, futureproofing]
11garbage1808.0612.0[garbage, greatpacificgarbagepatch]
12responsib1889.01135.0[responsible, responsibility, responsibly, res...
13carb1952.01526.0[decarbonisation, carbon, decarbonization, car...
14chang2148.01667.0[change, changing, climatechange, changes, exc...
15ocean2169.01629.0[ocean, theoceancleanup, oceans, oceanplastic,...
16plastic2320.01490.0[plastic, oceanplastic, plasticwaste, plasticp...
17neutral2382.01798.0[neutral, carbonneutral, neutrality, co2neutral]
18environment2391.01574.0[environment, environmental, unenvironment, en...
19green2393.01158.0[green, greenfuels, greener, greenfuel, greent...
20sulphur2828.01772.0[sulphur, lowsulphur]
21emissions2925.02046.0[emissions, carbonemissions, zeroemissions]
22zero2977.01646.0[zero, netzero, zerocarbon, zerocarbonship, ze...
23climate3046.02095.0[climateaction, climate, climatechange, climat...
24eco3074.01269.0[ecosystem, eco, maerskecodelivery, ecofriendl...
25mission3247.01950.0[emissions, mission, eucommission, carbonemiss...
26CO23390.02275.0[co2, co2neutral, co2emission]
27bio3687.01274.0[biofuel, biofuels, biohuts, biodiversity]
\n", "
" ], "text/plain": [ " root mean_ranking std_ranking \n", "0 challeng 420.0 264.0 \\\n", "1 SDG 423.0 0.0 \n", "2 ESG 636.0 0.0 \n", "3 recycling 860.0 154.0 \n", "4 reduc 1242.0 965.0 \n", "5 planet 1295.0 0.0 \n", "6 CSR 1371.0 0.0 \n", "7 sustainab 1527.0 1873.0 \n", "8 clean 1695.0 837.0 \n", "9 methanol 1700.0 1044.0 \n", "10 future 1770.0 1684.0 \n", "11 garbage 1808.0 612.0 \n", "12 responsib 1889.0 1135.0 \n", "13 carb 1952.0 1526.0 \n", "14 chang 2148.0 1667.0 \n", "15 ocean 2169.0 1629.0 \n", "16 plastic 2320.0 1490.0 \n", "17 neutral 2382.0 1798.0 \n", "18 environment 2391.0 1574.0 \n", "19 green 2393.0 1158.0 \n", "20 sulphur 2828.0 1772.0 \n", "21 emissions 2925.0 2046.0 \n", "22 zero 2977.0 1646.0 \n", "23 climate 3046.0 2095.0 \n", "24 eco 3074.0 1269.0 \n", "25 mission 3247.0 1950.0 \n", "26 CO2 3390.0 2275.0 \n", "27 bio 3687.0 1274.0 \n", "\n", " word_matches \n", "0 [challenges, challenge, challenging] \n", "1 [sdgs] \n", "2 [esg] \n", "3 [recycling, shiprecycling] \n", "4 [reduce, reducing, reduced, reduction, reducti... \n", "5 [planet] \n", "6 [csr] \n", "7 [sustainability, sustainable, sustainableshipp... \n", "8 [theoceancleanup, cleanup, clean, cleanseas, o... \n", "9 [methanol, emethanol] \n", "10 [future, futureproofing] \n", "11 [garbage, greatpacificgarbagepatch] \n", "12 [responsible, responsibility, responsibly, res... \n", "13 [decarbonisation, carbon, decarbonization, car... \n", "14 [change, changing, climatechange, changes, exc... \n", "15 [ocean, theoceancleanup, oceans, oceanplastic,... \n", "16 [plastic, oceanplastic, plasticwaste, plasticp... \n", "17 [neutral, carbonneutral, neutrality, co2neutral] \n", "18 [environment, environmental, unenvironment, en... \n", "19 [green, greenfuels, greener, greenfuel, greent... \n", "20 [sulphur, lowsulphur] \n", "21 [emissions, carbonemissions, zeroemissions] \n", "22 [zero, netzero, zerocarbon, zerocarbonship, ze... \n", "23 [climateaction, climate, climatechange, climat... \n", "24 [ecosystem, eco, maerskecodelivery, ecofriendl... \n", "25 [emissions, mission, eucommission, carbonemiss... \n", "26 [co2, co2neutral, co2emission] \n", "27 [biofuel, biofuels, biohuts, biodiversity] " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# sort values by ranking\n", "df = df.sort_values(by='mean_ranking').reset_index(drop=True)\n", "df" ] }, { "cell_type": "code", "execution_count": 7, "id": "7b3dbcf3-2d95-4a5e-b795-cea63da2a34a", "metadata": {}, "outputs": [], "source": [ "# save results\n", "df['mean_ranking'] = df['mean_ranking'].astype(int)\n", "df['std_ranking'] = df['std_ranking'].astype(int)\n", "df.to_csv('word_root_ranking.csv')" ] }, { "cell_type": "code", "execution_count": null, "id": "ef515886-a918-49a0-b9df-7f20bfe4cea4", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }