Pandas feladatok
This commit is contained in:
@ -137,17 +137,108 @@
|
||||
"- Hány ponttal magasabb a medencével (`Pool`) rendelkező szállodák átlagos értékelése (`Score`) a többi szálloda átlagos értékelésénél?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" Hotel name Nr. rooms Pool Gym Tennis court \\\n",
|
||||
"0 Circus Circus Hotel & Casino Las Vegas 3773 NO YES NO \n",
|
||||
"1 Circus Circus Hotel & Casino Las Vegas 3773 NO YES NO \n",
|
||||
"2 Circus Circus Hotel & Casino Las Vegas 3773 NO YES NO \n",
|
||||
"3 Circus Circus Hotel & Casino Las Vegas 3773 NO YES NO \n",
|
||||
"4 Circus Circus Hotel & Casino Las Vegas 3773 NO YES NO \n",
|
||||
"\n",
|
||||
" Spa Casino Traveler type Period of stay Score \n",
|
||||
"0 NO YES Friends Dec-Feb 5 \n",
|
||||
"1 NO YES Business Dec-Feb 3 \n",
|
||||
"2 NO YES Families Mar-May 5 \n",
|
||||
"3 NO YES Friends Mar-May 4 \n",
|
||||
"4 NO YES Solo Mar-May 4 \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"frame = pd.read_csv(\"hotels.txt\", sep=';')\n",
|
||||
"print(frame[:5])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hotel name\n",
|
||||
"The Venetian Las Vegas Hotel 96648\n",
|
||||
"Excalibur Hotel & Casino 95544\n",
|
||||
"Bellagio Las Vegas 94392\n",
|
||||
"Circus Circus Hotel & Casino Las Vegas 90552\n",
|
||||
"Caesars Palace 80352\n",
|
||||
"Name: Nr. rooms, dtype: int64\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"legtobb = frame.groupby(\"Hotel name\")[\"Nr. rooms\"].sum().sort_values(ascending=False)[:5]\n",
|
||||
"\n",
|
||||
"print(legtobb)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hotel name\n",
|
||||
"Wynn Las Vegas 4.625\n",
|
||||
"Name: Score, dtype: float64\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"scored = frame.groupby(\"Hotel name\")[\"Score\"].mean().sort_values(ascending=False)[:1]\n",
|
||||
"\n",
|
||||
"print(scored)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"0.9604166666666667\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"withspas = frame[frame[\"Pool\"] == \"YES\"][\"Score\"].mean()\n",
|
||||
"withoutspas = frame[frame[\"Pool\"] == \"NO\"][\"Score\"].mean()\n",
|
||||
"\n",
|
||||
"print(withspas - withoutspas)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
@ -161,7 +252,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.12.5"
|
||||
"version": "3.13.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
Reference in New Issue
Block a user