House Cleaning

This commit is contained in:
charlie-rasberry
2026-01-28 16:41:27 +00:00
parent 6cf36faf64
commit 8d3dee6d30
10 changed files with 150 additions and 483 deletions

View File

@@ -0,0 +1,266 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "739e61bf",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import re\n",
"from langdetect import detect, LangDetectException\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d9da1b98",
"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>review</th>\n",
" <th>rating</th>\n",
" <th>word_count</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>suddenly, the driver can't have my location an...</td>\n",
" <td>1</td>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>very cordial. and helped with a quick turnarou...</td>\n",
" <td>5</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>i have enjoyed traveling by uber my drivers ha...</td>\n",
" <td>5</td>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>app is good but main problem is the drivers ca...</td>\n",
" <td>1</td>\n",
" <td>23</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>very bad experience no customer service</td>\n",
" <td>1</td>\n",
" <td>6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" review rating word_count\n",
"0 suddenly, the driver can't have my location an... 1 23\n",
"1 very cordial. and helped with a quick turnarou... 5 11\n",
"2 i have enjoyed traveling by uber my drivers ha... 5 23\n",
"3 app is good but main problem is the drivers ca... 1 23\n",
"4 very bad experience no customer service 1 6"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('../data/uber_reviews_cleaned.csv')\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "91dc1d9a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.int64(6740)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(df['word_count'] > 100).sum()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "827b6435",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Max length review:\n",
"i've been using uber for a few years now and for the most part haven't had any problems the only problem i have ever had that was never resolved or explained to me was when i was refunded cancellation fee because the driver pulled into me and then literally looked in my face and drove away and canceled the ride.buy still charges me.a cancellation fee the problem wasn't being charged the fee because i was reimbursed a few minutes later the problem was that they gave me a $5 uber credit and i don't have a debit card so i use uber gift cards so i had a balance on the gift card of roughly $4.85 and is an uber credit of $5 but for some reason you can't combine them to use on a single gel ride and there is a minimum of i think $6 or $7 for a ride so i was never able to use the money i was reimbursed and the remaing balance on my gift card was not enough for a full ride and that was 4 months ago and still have not been able to get a response as to how i can use the funds remaining mn my uber account or the uber credits i was reimbursed. another time the driver took between 7-10 minutes to set the destination and begin driving and then when i was trying to help her with the directions because the gps was bringing us rather far out of the way to reach out destination she was very rude with me and then when we were approaching the turn that we needed to make and i warned her that it was coming up shortly and then said a few more times as we got closer to it she drove passed it the reason i was making sure she was aware of this was because we were in a rather busy highway and she would not be able to turn again for quite some time and i was already cutting it close to being late for work due to the delay in starting the trip and her failure to follow the direction i was giving her to get to.our destination so i said pull over into.the gas station and i will walk it'll be faster then driving at this point but she failed to pull into parking lot she just stopped in the middle.lf the highway granted we were in the right lane but she still put us both in a very dangerous situation and we were in a bad section of newark nj at around 10pm which for most people would put them in an uncomfortable position seeing how as the crime rate is extremely high in this area luckily i'm familiar with the residence of the neighborhood because i lived there for a few years in the past and then she notified uber that i was a disgruntled passenger and made her nervous from my reaction and in was warned to not let anything like this happen again. and the final problem.i had with uber was when my mother had ordered me.an uber through her account and during the ride we some.how started to discuss religion and i'm far from a religious person i do not even consider myself a member of any type of religion at all. but my driver was very dedicated to the religion he practiced so he got very upset and decided to call mother and tell her that i didn't not go the full distance of the original route he was hired to drive and that he had dropped me off a few blocks from where j was going to judge in some illegal activities (he knew i had some personal issues i was overcoming recently because i had mention it to him briefly in the beginning of the trip) and that he was not going to charge her the full ride amount because i did. ot cimplete the full distance and this caused my mother to become very upset with me and called me extremely untilni sent her a picture showing that i was in fact where i said i was going and the app showed that he did drop me off at the predetermined destination. sorry for the long post but out of the probably 100 or so ride i have used with uber those were the only 3 problems i have ever had and they all 3 were actually in the same week\n"
]
}
],
"source": [
"print(f\"Max length review:\\n{df.loc[df['word_count'].idxmax(), 'review']}\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7a811e3d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.int64(2839)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def has_spam_repetition(text):\n",
" return bool(re.search(r'(.)\\1{4,}', str(text)))\n",
"df['review'].apply(has_spam_repetition).sum()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "0a550434",
"metadata": {},
"outputs": [],
"source": [
"sample_check = df[df['word_count'] >= 10].sample(1000)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "ec7b2ec5",
"metadata": {},
"outputs": [],
"source": [
"def detect_language(text):\n",
" \"\"\"Detect language of text\"\"\"\n",
" try:\n",
" if pd.isna(text) or len(str(text).strip()) < 10:\n",
" return 'unknown'\n",
" return detect(str(text))\n",
" except LangDetectException:\n",
" return 'unknown'"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "d68dac67",
"metadata": {},
"outputs": [],
"source": [
"sample_check['lang'] = sample_check['review'].apply(detect_language)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "9a8a49b2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Language distribution in 10+ word reviews:\n",
"lang\n",
"en 956\n",
"es 7\n",
"pt 7\n",
"ar 4\n",
"id 3\n",
"da 3\n",
"bn 3\n",
"af 3\n",
"it 2\n",
"tl 2\n",
"tr 2\n",
"fr 1\n",
"ro 1\n",
"et 1\n",
"sv 1\n",
"nl 1\n",
"hi 1\n",
"pl 1\n",
"ta 1\n",
"Name: count, dtype: int64\n"
]
}
],
"source": [
"print(f\"\\nLanguage distribution in 10+ word reviews:\")\n",
"print(sample_check['lang'].value_counts())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "multitag",
"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.14.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}