Created
October 26, 2020 15:47
-
-
Save LowriWilliams/100d9fdb8f8870fd6f95cb5fdbae660f to your computer and use it in GitHub Desktop.
aspect_sa/aspects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 45, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<style scoped>\n", | |
| " .dataframe tbody tr th:only-of-type {\n", | |
| " vertical-align: middle;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe tbody tr th {\n", | |
| " vertical-align: top;\n", | |
| " }\n", | |
| "\n", | |
| " .dataframe thead th {\n", | |
| " text-align: right;\n", | |
| " }\n", | |
| "</style>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>Dominant_topic</th>\n", | |
| " <th>topic_name</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0</th>\n", | |
| " <td>5</td>\n", | |
| " <td>[battery charger]</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>1</th>\n", | |
| " <td>2</td>\n", | |
| " <td>[cell phone]</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>2</th>\n", | |
| " <td>1</td>\n", | |
| " <td>[screen protector]</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>3</th>\n", | |
| " <td>3</td>\n", | |
| " <td>[battery pack]</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>4</th>\n", | |
| " <td>4</td>\n", | |
| " <td>[car charger]</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " Dominant_topic topic_name\n", | |
| "0 5 [battery charger]\n", | |
| "1 2 [cell phone]\n", | |
| "2 1 [screen protector]\n", | |
| "3 3 [battery pack]\n", | |
| "4 4 [car charger]" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "all_topics = []\n", | |
| "\n", | |
| "for i in tmp['topic'].unique(): \n", | |
| " tmp_1 = tmp.loc[tmp['topic'] == i].reset_index()\n", | |
| " tmp_1 = tmp_1.sort_values('relevance_score', ascending=False).head(1)\n", | |
| "\n", | |
| " tmp_1['topic'] = tmp_1['topic'] + 1\n", | |
| " \n", | |
| " tmp_2 = []\n", | |
| " tmp_2.append(tmp_1['topic'].unique()[0])\n", | |
| " tmp_2.append(list(tmp_1['index'].unique()))\n", | |
| " all_topics.append(tmp_2)\n", | |
| "\n", | |
| "all_topics = pd.DataFrame(all_topics, columns=['Dominant_topic', 'topic_name'])\n", | |
| "display(all_topics)" | |
| ] | |
| } | |
| ], | |
| "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.7.2" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment