32 KiB
32 KiB
In [72]:
# load list of words related to sustainability
path = 'sustainability_words.txt'
word_list = list()
with open(path, 'r') as f:
for line in f.readlines():
word_list.append(line.replace('\n', ''))
word_list.sort()
print(word_list)['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']
In [73]:
# load word counts from tweets
import pandas as pd
word_df = pd.read_csv('word_count.csv', index_col=0)
word_dfOut [73]:
| word | counts | ratio | |
|---|---|---|---|
| 0 | maersk | 3207 | 0.04001 |
| 1 | is | 1025 | 0.01279 |
| 2 | more | 989 | 0.01234 |
| 3 | here | 825 | 0.01029 |
| 4 | trade | 642 | 0.00801 |
| ... | ... | ... | ... |
| 10920 | phase | 1 | 0.00001 |
| 10921 | agrichemicals | 1 | 0.00001 |
| 10922 | polluting | 1 | 0.00001 |
| 10923 | adams | 1 | 0.00001 |
| 10924 | maerskcapitalmarketsday | 1 | 0.00001 |
10925 rows × 3 columns
In [74]:
# load ignore list
ignore_list = list()
path = 'ignore_words.txt'
with open(path, 'r') as f:
for line in f.readlines():
ignore_list.append(line.replace('\n', ''))
ignore_list.sort()
print(ignore_list)['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']
In [76]:
import numpy as np
match_word_list = list()
mean_idx_list = list()
sigma_idx_list = list()
for i, word in enumerate(word_list):
# find index of matching words
contains_word_mask = word_df['word'].str.contains(word.lower())==True
counts_above_limit_mask = word_df['counts'].gt(1)
match_mask = contains_word_mask & counts_above_limit_mask
match_idx_list = word_df[match_mask].index.tolist()
# remove indices of unwanted words
remove_idx_list = list()
for idx in match_idx_list:
match_word = word_df.loc[idx, 'word']
if match_word in ignore_list:
remove_idx_list.append(idx)
for idx in remove_idx_list:
match_idx_list.remove(idx)
# store matched words
match_word_list.append(list())
for idx in match_idx_list:
match_word = word_df.loc[idx, 'word']
match_word_list[i].append(match_word)
# calculate mean and std of word ranking from located indices
mu = np.array(match_idx_list).mean().round()
mean_idx_list.append(mu)
sigma = np.array(match_idx_list).std().round()
sigma_idx_list.append(sigma)
# show example of results
idx = 0
print(word_list[idx])
print(match_word_list[idx])
print(mean_idx_list[idx])
print(sigma_idx_list[idx])CO2 ['co2', 'co2emission', 'co2neutral'] 3279.0 2165.0
In [77]:
df = pd.DataFrame({
'root': word_list,
'mean_ranking': mean_idx_list,
'std_ranking': sigma_idx_list,
'word_matches': match_word_list
})
dfOut [77]:
| root | mean_ranking | std_ranking | word_matches | |
|---|---|---|---|---|
| 0 | CO2 | 3279.0 | 2165.0 | [co2, co2emission, co2neutral] |
| 1 | CSR | 1345.0 | 0.0 | [csr] |
| 2 | ESG | 635.0 | 0.0 | [esg] |
| 3 | SDG | 423.0 | 0.0 | [sdgs] |
| 4 | bio | 3579.0 | 1252.0 | [biofuel, biofuels, biodiversity, biohuts] |
| 5 | carb | 1848.0 | 1396.0 | [decarbonisation, carbon, decarbonization, car... |
| 6 | challeng | 406.0 | 248.0 | [challenges, challenge, challenging] |
| 7 | chang | 2054.0 | 1563.0 | [change, changing, climatechange, changes, exc... |
| 8 | clean | 1709.0 | 859.0 | [theoceancleanup, cleanup, clean, cleanseas, o... |
| 9 | climate | 2943.0 | 1978.0 | [climateaction, climate, climatechange, climat... |
| 10 | eco | 3128.0 | 1228.0 | [ecosystem, eco, maerskecodelivery, ecofriendl... |
| 11 | emissions | 2912.0 | 2065.0 | [emissions, carbonemissions, zeroemissions] |
| 12 | environment | 2537.0 | 1736.0 | [environment, environmental, unenvironment, en... |
| 13 | future | 1626.0 | 1540.0 | [future, futureproofing] |
| 14 | garbage | 1772.0 | 511.0 | [garbage, greatpacificgarbagepatch] |
| 15 | green | 2580.0 | 1376.0 | [green, greenfuels, greener, greenfuel, greenl... |
| 16 | methanol | 1755.0 | 1110.0 | [methanol, emethanol] |
| 17 | mission | 3245.0 | 1937.0 | [emissions, mission, carbonemissions, eucommis... |
| 18 | neutral | 2384.0 | 1886.0 | [neutral, carbonneutral, neutrality, co2neutral] |
| 19 | ocean | 2217.0 | 1657.0 | [ocean, theoceancleanup, oceans, oceanplastic,... |
| 20 | planet | 1390.0 | 0.0 | [planet] |
| 21 | plastic | 2354.0 | 1587.0 | [plastic, oceanplastic, plasticwaste, plasticp... |
| 22 | recycling | 848.0 | 171.0 | [recycling, shiprecycling] |
| 23 | reduc | 1359.0 | 1199.0 | [reduce, reducing, reduced, reduction, reducti... |
| 24 | responsib | 1840.0 | 1093.0 | [responsible, responsibility, responsibly, res... |
| 25 | sulphur | 2572.0 | 1524.0 | [sulphur, lowsulphur] |
| 26 | sustainab | 1516.0 | 1825.0 | [sustainability, sustainable, sustainableshipp... |
| 27 | zero | 2972.0 | 1670.0 | [zero, netzero, zerocarbon, zerocarbonship, ze... |
In [78]:
# sort values by ranking
df = df.sort_values(by='mean_ranking').reset_index(drop=True)
dfOut [78]:
| root | mean_ranking | std_ranking | word_matches | |
|---|---|---|---|---|
| 0 | challeng | 406.0 | 248.0 | [challenges, challenge, challenging] |
| 1 | SDG | 423.0 | 0.0 | [sdgs] |
| 2 | ESG | 635.0 | 0.0 | [esg] |
| 3 | recycling | 848.0 | 171.0 | [recycling, shiprecycling] |
| 4 | CSR | 1345.0 | 0.0 | [csr] |
| 5 | reduc | 1359.0 | 1199.0 | [reduce, reducing, reduced, reduction, reducti... |
| 6 | planet | 1390.0 | 0.0 | [planet] |
| 7 | sustainab | 1516.0 | 1825.0 | [sustainability, sustainable, sustainableshipp... |
| 8 | future | 1626.0 | 1540.0 | [future, futureproofing] |
| 9 | clean | 1709.0 | 859.0 | [theoceancleanup, cleanup, clean, cleanseas, o... |
| 10 | methanol | 1755.0 | 1110.0 | [methanol, emethanol] |
| 11 | garbage | 1772.0 | 511.0 | [garbage, greatpacificgarbagepatch] |
| 12 | responsib | 1840.0 | 1093.0 | [responsible, responsibility, responsibly, res... |
| 13 | carb | 1848.0 | 1396.0 | [decarbonisation, carbon, decarbonization, car... |
| 14 | chang | 2054.0 | 1563.0 | [change, changing, climatechange, changes, exc... |
| 15 | ocean | 2217.0 | 1657.0 | [ocean, theoceancleanup, oceans, oceanplastic,... |
| 16 | plastic | 2354.0 | 1587.0 | [plastic, oceanplastic, plasticwaste, plasticp... |
| 17 | neutral | 2384.0 | 1886.0 | [neutral, carbonneutral, neutrality, co2neutral] |
| 18 | environment | 2537.0 | 1736.0 | [environment, environmental, unenvironment, en... |
| 19 | sulphur | 2572.0 | 1524.0 | [sulphur, lowsulphur] |
| 20 | green | 2580.0 | 1376.0 | [green, greenfuels, greener, greenfuel, greenl... |
| 21 | emissions | 2912.0 | 2065.0 | [emissions, carbonemissions, zeroemissions] |
| 22 | climate | 2943.0 | 1978.0 | [climateaction, climate, climatechange, climat... |
| 23 | zero | 2972.0 | 1670.0 | [zero, netzero, zerocarbon, zerocarbonship, ze... |
| 24 | eco | 3128.0 | 1228.0 | [ecosystem, eco, maerskecodelivery, ecofriendl... |
| 25 | mission | 3245.0 | 1937.0 | [emissions, mission, carbonemissions, eucommis... |
| 26 | CO2 | 3279.0 | 2165.0 | [co2, co2emission, co2neutral] |
| 27 | bio | 3579.0 | 1252.0 | [biofuel, biofuels, biodiversity, biohuts] |
In [79]:
# save results
df['mean_ranking'] = df['mean_ranking'].astype(int)
df['std_ranking'] = df['std_ranking'].astype(int)
df.to_csv('word_root_ranking.csv')In [ ]: